use operations for undo coalescence
This commit is contained in:
parent
52e0b2d163
commit
db4953c976
2 changed files with 13 additions and 11 deletions
|
|
@ -175,28 +175,30 @@ var Editor = function(renderer, session) {
|
||||||
this.$historyTracker = function(e) {
|
this.$historyTracker = function(e) {
|
||||||
if (!this.$mergeUndoDeltas)
|
if (!this.$mergeUndoDeltas)
|
||||||
return;
|
return;
|
||||||
var previous = this.previousCommand || {command:{}};
|
|
||||||
|
|
||||||
|
var prev = this.prevOp;
|
||||||
var mergeableCommands = ["backspace", "del", "insertstring"];
|
var mergeableCommands = ["backspace", "del", "insertstring"];
|
||||||
|
// previous command was the same
|
||||||
|
var shouldMerge = prev.command && (e.command.name == prev.command.name);
|
||||||
if (e.command.name == "insertstring") {
|
if (e.command.name == "insertstring") {
|
||||||
var text = e.args;
|
var text = e.args;
|
||||||
if (this.mergeNextCommand === undefined)
|
if (this.mergeNextCommand === undefined)
|
||||||
this.mergeNextCommand = true;
|
this.mergeNextCommand = true;
|
||||||
|
|
||||||
var shouldMerge = e.command.name == previous.command.name // previous command was the same
|
shouldMerge = shouldMerge
|
||||||
&& !this.cursorMoved // cursor was not moved since last command
|
|
||||||
&& this.mergeNextCommand // previous command allows to coalesce with
|
&& this.mergeNextCommand // previous command allows to coalesce with
|
||||||
&& (!/\s/.test(text) || /\s/.test(previous.args)) // previous insertion was of same type
|
&& (!/\s/.test(text) || /\s/.test(prev.args)) // previous insertion was of same type
|
||||||
|
|
||||||
this.mergeNextCommand = true;
|
this.mergeNextCommand = true;
|
||||||
} else {
|
} else {
|
||||||
var shouldMerge = e.command.name == previous.command.name // previous command was the same
|
shouldMerge = shouldMerge
|
||||||
&& mergeableCommands.indexOf(e.command.name) !== -1// the command is mergeable
|
&& mergeableCommands.indexOf(e.command.name) !== -1// the command is mergeable
|
||||||
&& !this.cursorMoved // cursor was not moved since last command
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.$mergeUndoDeltas != "always"
|
this.$mergeUndoDeltas != "always"
|
||||||
&& Date.now() - this.sequenceStartTime < 2000
|
&& Date.now() - this.sequenceStartTime > 2000
|
||||||
) {
|
) {
|
||||||
shouldMerge = false; // the sequence is too long
|
shouldMerge = false; // the sequence is too long
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +207,6 @@ var Editor = function(renderer, session) {
|
||||||
this.session.mergeUndoDeltas = true;
|
this.session.mergeUndoDeltas = true;
|
||||||
else if (mergeableCommands.indexOf(e.command.name) !== -1)
|
else if (mergeableCommands.indexOf(e.command.name) !== -1)
|
||||||
this.sequenceStartTime = Date.now();
|
this.sequenceStartTime = Date.now();
|
||||||
this.cursorMoved = false;
|
|
||||||
this.previousCommand = e;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,8 @@ var Selection = function(session) {
|
||||||
this.setSelectionAnchor(range.start.row, range.start.column);
|
this.setSelectionAnchor(range.start.row, range.start.column);
|
||||||
this.selectTo(range.end.row, range.end.column);
|
this.selectTo(range.end.row, range.end.column);
|
||||||
}
|
}
|
||||||
|
if (this.getRange().isEmpty())
|
||||||
|
this.$isEmpty = true;
|
||||||
this.$desiredColumn = null;
|
this.$desiredColumn = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue