MCPcopy
hub / github.com/witheve/Eve / addChangeToHistory

Function addChangeToHistory

src/codemirror.js:7951–7991  ·  view source on GitHub ↗
(doc, change, selAfter, opId)

Source from the content-addressed store, hash-verified

7949 // a single operation, ore are close together with an origin that
7950 // allows merging (starting with "+") into a single event.
7951 function addChangeToHistory(doc, change, selAfter, opId) {
7952 var hist = doc.history;
7953 hist.undone.length = 0;
7954 var time = +new Date, cur;
7955
7956 if ((hist.lastOp == opId ||
7957 hist.lastOrigin == change.origin && change.origin &&
7958 ((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
7959 change.origin.charAt(0) == "*")) &&
7960 (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
7961 // Merge this change into the last event
7962 var last = lst(cur.changes);
7963 if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
7964 // Optimized case for simple insertion -- don't want to add
7965 // new changesets for every character typed
7966 last.to = changeEnd(change);
7967 } else {
7968 // Add new sub-event
7969 cur.changes.push(historyChangeFromChange(doc, change));
7970 }
7971 } else {
7972 // Can not be merged, start a new event.
7973 var before = lst(hist.done);
7974 if (!before || !before.ranges)
7975 pushSelectionToHistory(doc.sel, hist.done);
7976 cur = {changes: [historyChangeFromChange(doc, change)],
7977 generation: hist.generation};
7978 hist.done.push(cur);
7979 while (hist.done.length > hist.undoDepth) {
7980 hist.done.shift();
7981 if (!hist.done[0].ranges) hist.done.shift();
7982 }
7983 }
7984 hist.done.push(selAfter);
7985 hist.generation = ++hist.maxGeneration;
7986 hist.lastModTime = hist.lastSelTime = time;
7987 hist.lastOp = hist.lastSelOp = opId;
7988 hist.lastOrigin = hist.lastSelOrigin = change.origin;
7989
7990 if (!last) signal(doc, "historyAdded");
7991 }
7992
7993 function selectionEventCanBeMerged(doc, origin, prev, sel) {
7994 var ch = origin.charAt(0);

Callers 2

makeChangeInnerFunction · 0.85
markTextFunction · 0.85

Calls 4

lastChangeEventFunction · 0.85
lstFunction · 0.85
historyChangeFromChangeFunction · 0.85
pushSelectionToHistoryFunction · 0.85

Tested by

no test coverage detected