use operations for undo coalescence

This commit is contained in:
nightwing 2013-06-17 16:38:00 +04:00
commit db4953c976
2 changed files with 13 additions and 11 deletions

View file

@ -175,38 +175,38 @@ var Editor = function(renderer, session) {
this.$historyTracker = function(e) {
if (!this.$mergeUndoDeltas)
return;
var previous = this.previousCommand || {command:{}};
var prev = this.prevOp;
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") {
var text = e.args;
if (this.mergeNextCommand === undefined)
this.mergeNextCommand = true;
var shouldMerge = e.command.name == previous.command.name // previous command was the same
&& !this.cursorMoved // cursor was not moved since last command
shouldMerge = shouldMerge
&& 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;
} 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
&& !this.cursorMoved // cursor was not moved since last command
}
if (
this.$mergeUndoDeltas != "always"
&& Date.now() - this.sequenceStartTime < 2000
&& Date.now() - this.sequenceStartTime > 2000
) {
shouldMerge = false; // the sequence is too long
}
if (shouldMerge)
this.session.mergeUndoDeltas = true;
else if (mergeableCommands.indexOf(e.command.name) !== -1)
this.sequenceStartTime = Date.now();
this.cursorMoved = false;
this.previousCommand = e;
};
/**

View file

@ -258,6 +258,8 @@ var Selection = function(session) {
this.setSelectionAnchor(range.start.row, range.start.column);
this.selectTo(range.end.row, range.end.column);
}
if (this.getRange().isEmpty())
this.$isEmpty = true;
this.$desiredColumn = null;
};