MCPcopy
hub / github.com/DHTMLX/gantt / addChangeToHistory

Function addChangeToHistory

samples/common/codehighlight/codemirror.js:4855–4896  ·  view source on GitHub ↗
(doc, change, selAfter, opId)

Source from the content-addressed store, hash-verified

4853 // a single operation, or are close together with an origin that
4854 // allows merging (starting with "+") into a single event.
4855 function addChangeToHistory(doc, change, selAfter, opId) {
4856 var hist = doc.history;
4857 hist.undone.length = 0;
4858 var time = +new Date, cur;
4859 var last;
4860
4861 if ((hist.lastOp == opId ||
4862 hist.lastOrigin == change.origin && change.origin &&
4863 ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
4864 change.origin.charAt(0) == "*")) &&
4865 (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
4866 // Merge this change into the last event
4867 last = lst(cur.changes);
4868 if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
4869 // Optimized case for simple insertion -- don't want to add
4870 // new changesets for every character typed
4871 last.to = changeEnd(change);
4872 } else {
4873 // Add new sub-event
4874 cur.changes.push(historyChangeFromChange(doc, change));
4875 }
4876 } else {
4877 // Can not be merged, start a new event.
4878 var before = lst(hist.done);
4879 if (!before || !before.ranges)
4880 { pushSelectionToHistory(doc.sel, hist.done); }
4881 cur = {changes: [historyChangeFromChange(doc, change)],
4882 generation: hist.generation};
4883 hist.done.push(cur);
4884 while (hist.done.length > hist.undoDepth) {
4885 hist.done.shift();
4886 if (!hist.done[0].ranges) { hist.done.shift(); }
4887 }
4888 }
4889 hist.done.push(selAfter);
4890 hist.generation = ++hist.maxGeneration;
4891 hist.lastModTime = hist.lastSelTime = time;
4892 hist.lastOp = hist.lastSelOp = opId;
4893 hist.lastOrigin = hist.lastSelOrigin = change.origin;
4894
4895 if (!last) { signal(doc, "historyAdded"); }
4896 }
4897
4898 function selectionEventCanBeMerged(doc, origin, prev, sel) {
4899 var ch = origin.charAt(0);

Callers 2

makeChangeInnerFunction · 0.85
markTextFunction · 0.85

Calls 7

lastChangeEventFunction · 0.85
lstFunction · 0.85
cmpFunction · 0.85
changeEndFunction · 0.85
historyChangeFromChangeFunction · 0.85
pushSelectionToHistoryFunction · 0.85
signalFunction · 0.85

Tested by

no test coverage detected