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

Function rebaseHistArray

static/mergely/lib/codemirror.js:8075–8101  ·  view source on GitHub ↗
(array, from, to, diff)

Source from the content-addressed store, hash-verified

8073 // reallocate them all on every rebase, but also avoid problems with
8074 // shared position objects being unsafely updated.
8075 function rebaseHistArray(array, from, to, diff) {
8076 for (var i = 0; i < array.length; ++i) {
8077 var sub = array[i], ok = true;
8078 if (sub.ranges) {
8079 if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
8080 for (var j = 0; j < sub.ranges.length; j++) {
8081 rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
8082 rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
8083 }
8084 continue;
8085 }
8086 for (var j = 0; j < sub.changes.length; ++j) {
8087 var cur = sub.changes[j];
8088 if (to < cur.from.line) {
8089 cur.from = Pos(cur.from.line + diff, cur.from.ch);
8090 cur.to = Pos(cur.to.line + diff, cur.to.ch);
8091 } else if (from <= cur.to.line) {
8092 ok = false;
8093 break;
8094 }
8095 }
8096 if (!ok) {
8097 array.splice(0, i + 1);
8098 i = 0;
8099 }
8100 }
8101 }
8102
8103 function rebaseHist(hist, change) {
8104 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