From 89020be0ee72f1f6fd00441b941c6155d5dc9fc7 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 10 Feb 2011 16:23:38 -0500 Subject: [PATCH] Fix a race. --HG-- branch : groups --- common/content/editor.js | 4 ++++ common/content/modes.js | 4 +++- common/content/mow.js | 27 +++++++++++++++------------ common/modules/base.jsm | 17 ++++++++--------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/common/content/editor.js b/common/content/editor.js index a8938b02..1e5a62b3 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -36,6 +36,8 @@ var Editor = Module("editor", { let text = dactyl.clipboardRead(clipboard); if (!text) return; + if (isinstance(elem, [HTMLInputElement, XULTextBoxElement])) + text = text.replace(/\n+/g, ""); // This is a hacky fix - but it works. // in the bottom of a long textarea bounces up @@ -46,7 +48,9 @@ var Editor = Module("editor", { let end = elem.selectionEnd; let value = elem.value.substring(0, start) + text + elem.value.substring(end); elem.value = value; + Editor.getEditor(elem).rootElement.firstChild.textContent = value; + elem.selectionStart = Math.min(start + (toStart ? 0 : text.length), elem.value.length); elem.selectionEnd = elem.selectionStart; diff --git a/common/content/modes.js b/common/content/modes.js index b9ce2fc9..64334921 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -245,6 +245,8 @@ var Modes = Module("modes", { getCharModes: function (chr) (this.modeChars[chr] || []).slice(), + have: function have(mode) this._modeStack.some(function (m) isinstance(m.main, mode)), + matchModes: function (obj) this._modes.filter(function (mode) Object.keys(obj) .every(function (k) obj[k] == (mode[k] || false))), @@ -397,7 +399,7 @@ var Modes = Module("modes", { }, isinstance: function (obj) - this.allBases.indexOf(obj) >= 0 || callable(obj) && this instanceof obj, + this === obj || this.allBases.indexOf(obj) >= 0 || callable(obj) && this instanceof obj, allBases: Class.memoize(function () { let seen = {}, res = [], queue = this.bases; diff --git a/common/content/mow.js b/common/content/mow.js index e526efda..5b42c5dd 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -10,25 +10,28 @@ var MOW = Module("mow", { init: function () { this._resize = Timer(20, 400, function () { - if (this.visible) { + if (this.visible) this.resize(false); + + if (this.visible && isinstance(modes.main, modes.OUTPUT_MULTILINE)) this.updateMorePrompt(); - } }, this); this._timer = Timer(20, 400, function () { - this.resize(true); + if (modes.have(modes.OUTPUT_MULTILINE)) { + this.resize(true); - if (options["more"] && this.isScrollable(1)) { - // start the last executed command's output at the top of the screen - let elements = this.document.getElementsByClassName("ex-command-output"); - elements[elements.length - 1].scrollIntoView(true); + if (options["more"] && this.isScrollable(1)) { + // start the last executed command's output at the top of the screen + let elements = this.document.getElementsByClassName("ex-command-output"); + elements[elements.length - 1].scrollIntoView(true); + } + else + this.body.scrollTop = this.body.scrollHeight; + + dactyl.focus(this.window); + this.updateMorePrompt(); } - else - this.body.scrollTop = this.body.scrollHeight; - - dactyl.focus(this.window); - this.updateMorePrompt(); }, this); events.listen(window, this, "windowEvents"); diff --git a/common/modules/base.jsm b/common/modules/base.jsm index d91b41dd..ea894b8c 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -440,25 +440,24 @@ function isinstance(object, interfaces) { if (object == null) return false; - interfaces = Array.concat(interfaces); - for (var i = 0; i < interfaces.length; i++) { - if (typeof interfaces[i] === "string") { - if (objproto.toString.call(object) === "[object " + interfaces[i] + "]") + return Array.concat(interfaces).some(function isinstance_some(iface) { + if (typeof iface === "string") { + if (objproto.toString.call(object) === "[object " + iface + "]") return true; } else if (typeof object === "object" && "isinstance" in object && object.isinstance !== isinstance) { - if (object.isinstance(interfaces[i])) + if (object.isinstance(iface)) return true; } else { - if (object instanceof interfaces[i]) + if (object instanceof iface) return true; var type = isinstance_types[typeof object]; - if (type && isSubclass(interfaces[i], type)) + if (type && isSubclass(iface, type)) return true; } - } - return false; + return false; + }); } /**