MCPcopy Create free account
hub / github.com/TruthHun/BookStack / skipAtomic

Function skipAtomic

static/editor.md/lib/codemirror/lib/codemirror.js:2145–2193  ·  view source on GitHub ↗
(doc, pos, bias, mayClear)

Source from the content-addressed store, hash-verified

2143
2144 // Ensure a given position is not inside an atomic range.
2145 function skipAtomic(doc, pos, bias, mayClear) {
2146 var flipped = false, curPos = pos;
2147 var dir = bias || 1;
2148 doc.cantEdit = false;
2149 search: for (;;) {
2150 var line = getLine(doc, curPos.line);
2151 if (line.markedSpans) {
2152 for (var i = 0; i < line.markedSpans.length; ++i) {
2153 var sp = line.markedSpans[i], m = sp.marker;
2154 if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
2155 (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
2156 if (mayClear) {
2157 signal(m, "beforeCursorEnter");
2158 if (m.explicitlyCleared) {
2159 if (!line.markedSpans) break;
2160 else {--i; continue;}
2161 }
2162 }
2163 if (!m.atomic) continue;
2164 var newPos = m.find(dir < 0 ? -1 : 1);
2165 if (cmp(newPos, curPos) == 0) {
2166 newPos.ch += dir;
2167 if (newPos.ch < 0) {
2168 if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
2169 else newPos = null;
2170 } else if (newPos.ch > line.text.length) {
2171 if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
2172 else newPos = null;
2173 }
2174 if (!newPos) {
2175 if (flipped) {
2176 // Driven in a corner -- no valid cursor position found at all
2177 // -- try again *with* clearing, if we didn't already
2178 if (!mayClear) return skipAtomic(doc, pos, bias, true);
2179 // Otherwise, turn off editing until further notice, and return the start of the doc
2180 doc.cantEdit = true;
2181 return Pos(doc.first, 0);
2182 }
2183 flipped = true; newPos = pos; dir = -dir;
2184 }
2185 }
2186 curPos = newPos;
2187 continue search;
2188 }
2189 }
2190 }
2191 return curPos;
2192 }
2193 }
2194
2195 // SELECTION DRAWING
2196

Callers 2

skipAtomicInSelectionFunction · 0.70
findPosHFunction · 0.70

Calls 3

getLineFunction · 0.70
clipPosFunction · 0.70
cmpFunction · 0.50

Tested by

no test coverage detected