MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / skipAtomicInner

Function skipAtomicInner

lib/web/CodeMirror/src/model/selection_updates.js:149–186  ·  view source on GitHub ↗
(doc, pos, oldPos, dir, mayClear)

Source from the content-addressed store, hash-verified

147}
148
149function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
150 let line = getLine(doc, pos.line)
151 if (line.markedSpans) for (let i = 0; i < line.markedSpans.length; ++i) {
152 let sp = line.markedSpans[i], m = sp.marker
153
154 // Determine if we should prevent the cursor being placed to the left/right of an atomic marker
155 // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it
156 // is with selectLeft/Right
157 let preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft
158 let preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight
159
160 if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
161 (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
162 if (mayClear) {
163 signal(m, "beforeCursorEnter")
164 if (m.explicitlyCleared) {
165 if (!line.markedSpans) break
166 else {--i; continue}
167 }
168 }
169 if (!m.atomic) continue
170
171 if (oldPos) {
172 let near = m.find(dir < 0 ? 1 : -1), diff
173 if (dir < 0 ? preventCursorRight : preventCursorLeft)
174 near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null)
175 if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
176 return skipAtomicInner(doc, near, pos, dir, mayClear)
177 }
178
179 let far = m.find(dir < 0 ? -1 : 1)
180 if (dir < 0 ? preventCursorLeft : preventCursorRight)
181 far = movePos(doc, far, dir, far.line == pos.line ? line : null)
182 return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
183 }
184 }
185 return pos
186}
187
188// Ensure a given position is not inside an atomic range.
189export function skipAtomic(doc, pos, oldPos, bias, mayClear) {

Callers 1

skipAtomicFunction · 0.70

Calls 5

getLineFunction · 0.90
signalFunction · 0.90
cmpFunction · 0.90
movePosFunction · 0.70
findMethod · 0.45

Tested by

no test coverage detected