From 7028b8b84e749420444e9a855fd6cc477d010272 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 7 Oct 2011 02:03:16 -0400 Subject: [PATCH] Don't save history and completion changes in kill ring. --- common/content/commandline.js | 47 ++++++++++++++++++++--------------- common/content/editor.js | 8 +++--- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/common/content/commandline.js b/common/content/commandline.js index cff3ab79..00f4a136 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -966,11 +966,15 @@ var CommandLine = Module("commandline", { * @param {string} val The new value. */ replace: function replace(val) { - this.input.dactylKeyPress = undefined; - if (this.completions) - this.completions.previewClear(); - this.input.value = val; - this.session.onHistory(val); + editor.withSavedValues(["skipSave"], function () { + editor.skipSave = true; + + this.input.dactylKeyPress = undefined; + if (this.completions) + this.completions.previewClear(); + this.input.value = val; + this.session.onHistory(val); + }, this); }, /** @@ -1116,25 +1120,28 @@ var CommandLine = Module("commandline", { * @param {string} value The value to insert. */ setCompletion: function setCompletion(offset, value) { - this.previewClear(); + editor.withSavedValues(["skipSave"], function () { + editor.skipSave = true; + this.previewClear(); - if (value == null) - var [input, caret] = [this.originalValue, this.originalCaret]; - else { - input = this.getCompletion(offset, value); - caret = offset + value.length; - } + if (value == null) + var [input, caret] = [this.originalValue, this.originalCaret]; + else { + input = this.getCompletion(offset, value); + caret = offset + value.length; + } - // Change the completion text. - // The second line is a hack to deal with some substring - // preview corner cases. - commandline.widgets.active.command.value = input; - this.editor.selection.focusNode.textContent = input; + // Change the completion text. + // The second line is a hack to deal with some substring + // preview corner cases. + commandline.widgets.active.command.value = input; + this.editor.selection.focusNode.textContent = input; - this.caret = caret; - this._caret = this.caret; + this.caret = caret; + this._caret = this.caret; - this.input.dactylKeyPress = undefined; + this.input.dactylKeyPress = undefined; + }, this); }, /** diff --git a/common/content/editor.js b/common/content/editor.js index 3d47936b..c7122ecd 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -45,6 +45,8 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { get registers() storage.newMap("registers", { privateData: true, store: true }), get registerRing() storage.newArray("register-ring", { privateData: true, store: true }), + skipSave: false, + // Fixme: Move off this object. currentRegister: null, @@ -519,15 +521,15 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { // nsIEditActionListener: WillDeleteNode: util.wrapCallback(function WillDeleteNode(node) { - if (node.textContent) + if (!editor.skipSave && node.textContent) this.setRegister(0, node); }), WillDeleteSelection: util.wrapCallback(function WillDeleteSelection(selection) { - if (!selection.isCollapsed) + if (!editor.skipSave && !selection.isCollapsed) this.setRegister(0, selection); }), WillDeleteText: util.wrapCallback(function WillDeleteText(node, start, length) { - if (length) + if (!editor.skipSave && length) this.setRegister(0, node.textContent.substr(start, length)); }) }, {