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

Function copyHistoryArray

static/editor.md/lib/codemirror/lib/codemirror.js:7803–7824  ·  view source on GitHub ↗
(events, newGroup, instantiateSel)

Source from the content-addressed store, hash-verified

7801 // Used both to provide a JSON-safe object in .getHistory, and, when
7802 // detaching a document, to split the history in two
7803 function copyHistoryArray(events, newGroup, instantiateSel) {
7804 for (var i = 0, copy = []; i < events.length; ++i) {
7805 var event = events[i];
7806 if (event.ranges) {
7807 copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
7808 continue;
7809 }
7810 var changes = event.changes, newChanges = [];
7811 copy.push({changes: newChanges});
7812 for (var j = 0; j < changes.length; ++j) {
7813 var change = changes[j], m;
7814 newChanges.push({from: change.from, to: change.to, text: change.text});
7815 if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
7816 if (indexOf(newGroup, Number(m[1])) > -1) {
7817 lst(newChanges)[prop] = change[prop];
7818 delete change[prop];
7819 }
7820 }
7821 }
7822 }
7823 return copy;
7824 }
7825
7826 // Rebasing/resetting history to deal with externally-sourced changes
7827

Callers 1

codemirror.jsFile · 0.70

Calls 2

indexOfFunction · 0.70
lstFunction · 0.70

Tested by

no test coverage detected