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

Function rebaseHistArray

static/editor.md/lib/codemirror/lib/codemirror.js:7844–7870  ·  view source on GitHub ↗
(array, from, to, diff)

Source from the content-addressed store, hash-verified

7842 // reallocate them all on every rebase, but also avoid problems with
7843 // shared position objects being unsafely updated.
7844 function rebaseHistArray(array, from, to, diff) {
7845 for (var i = 0; i < array.length; ++i) {
7846 var sub = array[i], ok = true;
7847 if (sub.ranges) {
7848 if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
7849 for (var j = 0; j < sub.ranges.length; j++) {
7850 rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
7851 rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
7852 }
7853 continue;
7854 }
7855 for (var j = 0; j < sub.changes.length; ++j) {
7856 var cur = sub.changes[j];
7857 if (to < cur.from.line) {
7858 cur.from = Pos(cur.from.line + diff, cur.from.ch);
7859 cur.to = Pos(cur.to.line + diff, cur.to.ch);
7860 } else if (from <= cur.to.line) {
7861 ok = false;
7862 break;
7863 }
7864 }
7865 if (!ok) {
7866 array.splice(0, i + 1);
7867 i = 0;
7868 }
7869 }
7870 }
7871
7872 function rebaseHist(hist, change) {
7873 var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;

Callers 1

rebaseHistFunction · 0.70

Calls 1

rebaseHistSelSingleFunction · 0.70

Tested by

no test coverage detected