MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / skipAtomic

Function skipAtomic

static/js/codemirror/codemirror.js:2358–2403  ·  view source on GitHub ↗
(doc, pos, bias, mayClear)

Source from the content-addressed store, hash-verified

2356 }
2357
2358 function skipAtomic(doc, pos, bias, mayClear) {
2359 var flipped = false, curPos = pos;
2360 var dir = bias || 1;
2361 doc.cantEdit = false;
2362 search: for (;;) {
2363 var line = getLine(doc, curPos.line), toClear;
2364 if (line.markedSpans) {
2365 for (var i = 0; i < line.markedSpans.length; ++i) {
2366 var sp = line.markedSpans[i], m = sp.marker;
2367 if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
2368 (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
2369 if (mayClear && m.clearOnEnter) {
2370 (toClear || (toClear = [])).push(m);
2371 continue;
2372 } else if (!m.atomic) continue;
2373 var newPos = m.find()[dir < 0 ? "from" : "to"];
2374 if (posEq(newPos, curPos)) {
2375 newPos.ch += dir;
2376 if (newPos.ch < 0) {
2377 if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
2378 else newPos = null;
2379 } else if (newPos.ch > line.text.length) {
2380 if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
2381 else newPos = null;
2382 }
2383 if (!newPos) {
2384 if (flipped) {
2385 // Driven in a corner -- no valid cursor position found at all
2386 // -- try again *with* clearing, if we didn't already
2387 if (!mayClear) return skipAtomic(doc, pos, bias, true);
2388 // Otherwise, turn off editing until further notice, and return the start of the doc
2389 doc.cantEdit = true;
2390 return Pos(doc.first, 0);
2391 }
2392 flipped = true; newPos = pos; dir = -dir;
2393 }
2394 }
2395 curPos = newPos;
2396 continue search;
2397 }
2398 }
2399 if (toClear) for (var i = 0; i < toClear.length; ++i) toClear[i].clear();
2400 }
2401 return curPos;
2402 }
2403 }
2404
2405 // SCROLLING
2406

Callers 2

setSelectionFunction · 0.85
findPosHFunction · 0.85

Calls 7

getLineFunction · 0.85
posEqFunction · 0.85
clipPosFunction · 0.85
PosFunction · 0.85
pushMethod · 0.45
findMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected