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

Function rebaseHistArray

lib/web/CodeMirror/src/model/changes.js:295–321  ·  view source on GitHub ↗
(array, from, to, diff)

Source from the content-addressed store, hash-verified

293// reallocate them all on every rebase, but also avoid problems with
294// shared position objects being unsafely updated.
295function rebaseHistArray(array, from, to, diff) {
296 for (let i = 0; i < array.length; ++i) {
297 let sub = array[i], ok = true
298 if (sub.ranges) {
299 if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
300 for (let j = 0; j < sub.ranges.length; j++) {
301 rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
302 rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
303 }
304 continue
305 }
306 for (let j = 0; j < sub.changes.length; ++j) {
307 let cur = sub.changes[j]
308 if (to < cur.from.line) {
309 cur.from = Pos(cur.from.line + diff, cur.from.ch)
310 cur.to = Pos(cur.to.line + diff, cur.to.ch)
311 } else if (from <= cur.to.line) {
312 ok = false
313 break
314 }
315 }
316 if (!ok) {
317 array.splice(0, i + 1)
318 i = 0
319 }
320 }
321}
322
323function rebaseHist(hist, change) {
324 let from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1

Callers 1

rebaseHistFunction · 0.70

Calls 3

PosFunction · 0.90
deepCopyMethod · 0.80
rebaseHistSelSingleFunction · 0.70

Tested by

no test coverage detected