MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / addToHistory

Function addToHistory

static/js/codemirror/codemirror.js:4681–4719  ·  view source on GitHub ↗
(doc, change, selAfter, opId)

Source from the content-addressed store, hash-verified

4679 }
4680
4681 function addToHistory(doc, change, selAfter, opId) {
4682 var hist = doc.history;
4683 hist.undone.length = 0;
4684 var time = +new Date, cur = lst(hist.done);
4685
4686 if (cur &&
4687 (hist.lastOp == opId ||
4688 hist.lastOrigin == change.origin && change.origin &&
4689 ((change.origin.charAt(0) == "+" && hist.lastTime > time - 600) || change.origin.charAt(0) == "*"))) {
4690 // Merge this change into the last event
4691 var last = lst(cur.changes);
4692 if (posEq(change.from, change.to) && posEq(change.from, last.to)) {
4693 // Optimized case for simple insertion -- don't want to add
4694 // new changesets for every character typed
4695 last.to = changeEnd(change);
4696 } else {
4697 // Add new sub-event
4698 cur.changes.push(historyChangeFromChange(doc, change));
4699 }
4700 cur.anchorAfter = selAfter.anchor; cur.headAfter = selAfter.head;
4701 } else {
4702 // Can not be merged, start a new event.
4703 cur = {changes: [historyChangeFromChange(doc, change)],
4704 anchorBefore: doc.sel.anchor, headBefore: doc.sel.head,
4705 anchorAfter: selAfter.anchor, headAfter: selAfter.head};
4706 hist.done.push(cur);
4707 while (hist.done.length > hist.undoDepth)
4708 hist.done.shift();
4709 if (hist.dirtyCounter < 0)
4710 // The user has made a change after undoing past the last clean state.
4711 // We can never get back to a clean state now until markClean() is called.
4712 hist.dirtyCounter = NaN;
4713 else
4714 hist.dirtyCounter++;
4715 }
4716 hist.lastTime = time;
4717 hist.lastOp = opId;
4718 hist.lastOrigin = change.origin;
4719 }
4720
4721 function removeClearedSpans(spans) {
4722 if (!spans) return null;

Callers 1

makeChangeNoReadonlyFunction · 0.85

Calls 5

lstFunction · 0.85
posEqFunction · 0.85
changeEndFunction · 0.85
historyChangeFromChangeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected