MCPcopy Create free account
hub / github.com/sql-js/sql.js / skipAtomic

Function skipAtomic

GUI/codemirror/lib/codemirror.js:1187–1235  ·  view source on GitHub ↗
(doc, pos, bias, mayClear)

Source from the content-addressed store, hash-verified

1185
1186 // Ensure a given position is not inside an atomic range.
1187 function skipAtomic(doc, pos, bias, mayClear) {
1188 var flipped = false, curPos = pos;
1189 var dir = bias || 1;
1190 doc.cantEdit = false;
1191 search: for (;;) {
1192 var line = getLine(doc, curPos.line);
1193 if (line.markedSpans) {
1194 for (var i = 0; i < line.markedSpans.length; ++i) {
1195 var sp = line.markedSpans[i], m = sp.marker;
1196 if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
1197 (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
1198 if (mayClear) {
1199 signal(m, "beforeCursorEnter");
1200 if (m.explicitlyCleared) {
1201 if (!line.markedSpans) break;
1202 else {--i; continue;}
1203 }
1204 }
1205 if (!m.atomic) continue;
1206 var newPos = m.find(dir < 0 ? -1 : 1);
1207 if (cmp(newPos, curPos) == 0) {
1208 newPos.ch += dir;
1209 if (newPos.ch < 0) {
1210 if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
1211 else newPos = null;
1212 } else if (newPos.ch > line.text.length) {
1213 if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
1214 else newPos = null;
1215 }
1216 if (!newPos) {
1217 if (flipped) {
1218 // Driven in a corner -- no valid cursor position found at all
1219 // -- try again *with* clearing, if we didn't already
1220 if (!mayClear) return skipAtomic(doc, pos, bias, true);
1221 // Otherwise, turn off editing until further notice, and return the start of the doc
1222 doc.cantEdit = true;
1223 return Pos(doc.first, 0);
1224 }
1225 flipped = true; newPos = pos; dir = -dir;
1226 }
1227 }
1228 curPos = newPos;
1229 continue search;
1230 }
1231 }
1232 }
1233 return curPos;
1234 }
1235 }
1236
1237 // SELECTION DRAWING
1238

Callers 2

skipAtomicInSelectionFunction · 0.85
findPosHFunction · 0.85

Calls 2

getLineFunction · 0.85
clipPosFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…