MCPcopy
hub / github.com/csev/py4e / addChangeToHistory

Function addChangeToHistory

tools/pythonauto/static/codemirrorepl/codemirror.js:6586–6626  ·  view source on GitHub ↗
(doc, change, selAfter, opId)

Source from the content-addressed store, hash-verified

6584 // a single operation, ore are close together with an origin that
6585 // allows merging (starting with "+") into a single event.
6586 function addChangeToHistory(doc, change, selAfter, opId) {
6587 var hist = doc.history;
6588 hist.undone.length = 0;
6589 var time = +new Date, cur;
6590
6591 if ((hist.lastOp == opId ||
6592 hist.lastOrigin == change.origin && change.origin &&
6593 ((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
6594 change.origin.charAt(0) == "*")) &&
6595 (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
6596 // Merge this change into the last event
6597 var last = lst(cur.changes);
6598 if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
6599 // Optimized case for simple insertion -- don't want to add
6600 // new changesets for every character typed
6601 last.to = changeEnd(change);
6602 } else {
6603 // Add new sub-event
6604 cur.changes.push(historyChangeFromChange(doc, change));
6605 }
6606 } else {
6607 // Can not be merged, start a new event.
6608 var before = lst(hist.done);
6609 if (!before || !before.ranges)
6610 pushSelectionToHistory(doc.sel, hist.done);
6611 cur = {changes: [historyChangeFromChange(doc, change)],
6612 generation: hist.generation};
6613 hist.done.push(cur);
6614 while (hist.done.length > hist.undoDepth) {
6615 hist.done.shift();
6616 if (!hist.done[0].ranges) hist.done.shift();
6617 }
6618 }
6619 hist.done.push(selAfter);
6620 hist.generation = ++hist.maxGeneration;
6621 hist.lastModTime = hist.lastSelTime = time;
6622 hist.lastOp = opId;
6623 hist.lastOrigin = hist.lastSelOrigin = change.origin;
6624
6625 if (!last) signal(doc, "historyAdded");
6626 }
6627
6628 function selectionEventCanBeMerged(doc, origin, prev, sel) {
6629 var ch = origin.charAt(0);

Callers 2

makeChangeInnerFunction · 0.85
markTextFunction · 0.85

Calls 7

lastChangeEventFunction · 0.85
cmpFunction · 0.85
pushSelectionToHistoryFunction · 0.85
signalFunction · 0.85
lstFunction · 0.70
historyChangeFromChangeFunction · 0.70
shiftMethod · 0.45

Tested by

no test coverage detected