From db4953c976ebd05c2fbf311a456ad200137b08f3 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 17 Jun 2013 16:38:00 +0400 Subject: [PATCH] use operations for undo coalescence --- lib/ace/editor.js | 22 +++++++++++----------- lib/ace/selection.js | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 572425ea..ff3bb3cd 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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; }; /** diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 68a22a5c..50a5bd0e 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -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; };