From b6077640122567645cef92f6cdb609293bbdd598 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 11 Nov 2009 19:18:04 -0500 Subject: [PATCH] Add Classeditor.jssetTimeout. Fix some broken timeouts. --- common/content/base.js | 20 +++++++------------- common/content/commandline.js | 20 +++++++++++--------- common/content/events.js | 2 +- common/content/finder.js | 10 +++++----- common/content/hints.js | 6 +++--- common/content/statusline.js | 2 +- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/common/content/base.js b/common/content/base.js index 14d3cf68..686009be 100644 --- a/common/content/base.js +++ b/common/content/base.js @@ -8,19 +8,6 @@ const Ci = Components.interfaces; const Cr = Components.results; const Cu = Components.utils; -// TODO: Move to liberator. -function setTimeout(callback, timeout, self) { - function target() { - try { - callback.call(self); - } - catch (e) { - liberator.reportError(e); - } - } - return window.setTimeout(target, timeout); -} - function array(obj) { if (isgenerator(obj)) obj = [k for (k in obj)]; @@ -288,7 +275,14 @@ function Class() { Class.toString = function () "[class " + this.constructor.name + "]", Class.prototype = { init: function() {}, + toString: function () "[instance " + this.constructor.name + "]", + + setTimeout: function (callback, timeout) { + const self = this; + function target() callback.call(self); + return window.setTimeout(target, timeout); + } }; const Struct = Class("Struct", { diff --git a/common/content/commandline.js b/common/content/commandline.js index cd9697e0..3bfe0b9c 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -596,7 +596,7 @@ const CommandLine = Module("commandline", { this._multilineInputWidget.value = ""; this._autosizeMultilineInputWidget(); - setTimeout(function () { this._multilineInputWidget.focus(); }, 10); + this.setTimeout(function () { this._multilineInputWidget.focus(); }, 10); }, /** @@ -608,18 +608,17 @@ const CommandLine = Module("commandline", { * @private */ onEvent: function onEvent(event) { - const self = this; let command = this.command; if (event.type == "blur") { // prevent losing focus, there should be a better way, but it just didn't work otherwise - setTimeout(function () { - if (self._commandShown() && event.originalTarget == self._commandWidget.inputField) - self._commandWidget.inputField.focus(); + this.setTimeout(function () { + if (this._commandShown() && event.originalTarget == this._commandWidget.inputField) + this._commandWidget.inputField.focus(); }, 0); } else if (event.type == "focus") { - if (!self._commandShown() && event.target == self._commandWidget.inputField) { + if (!this._commandShown() && event.target == this._commandWidget.inputField) { event.target.blur(); liberator.beep(); } @@ -711,7 +710,7 @@ const CommandLine = Module("commandline", { } else if (event.type == "blur") { if (modes.extended & modes.INPUT_MULTILINE) - setTimeout(function () { this._multilineInputWidget.inputField.focus(); }, 0); + this.setTimeout(function () { this._multilineInputWidget.inputField.focus(); }, 0); } else if (event.type == "input") this._autosizeMultilineInputWidget(); @@ -1038,6 +1037,7 @@ const CommandLine = Module("commandline", { if (liberator.has("sanitizer") && (timespan || options["sanitizetimespan"])) range = sanitizer.getClearRange(timespan || options["sanitizetimespan"]); + const self = this; this.store.mutate("filter", function (item) { let timestamp = (item.timestamp || Date.now()/1000) * 1000; return !line.privateData || timestamp < self.range[0] || timestamp > self.range[1]; @@ -1653,16 +1653,18 @@ const ItemList = Class("ItemList", { _dom: function (xml, map) util.xmlToDom(xml, this._doc, map), _autoSize: function () { - const self = this; if (this._container.collapsed) this._div.style.minWidth = document.getElementById("liberator-commandline").scrollWidth + "px"; + this._minHeight = Math.max(this._minHeight, this._divNodes.completions.getBoundingClientRect().bottom); this._container.height = this._minHeight; + if (this._container.collapsed) this._div.style.minWidth = ""; + // FIXME: Belongs elsewhere. commandline.updateOutputHeight(false); - setTimeout(function () { self._container.height -= commandline.getSpaceNeeded() }, 0); + this.setTimeout(function () { this._container.height -= commandline.getSpaceNeeded() }, 0); }, _getCompletion: function (index) this._completionElements.snapshotItem(index - this._startIndex), diff --git a/common/content/events.js b/common/content/events.js index b5ff96b1..8a150256 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -880,7 +880,7 @@ const Events = Module("events", { events.feedingKeys = false; if (modes.isReplaying) { modes.isReplaying = false; - setTimeout(function () { liberator.echomsg("Canceled playback of macro '" + this._lastMacro + "'"); }, 100); + this.setTimeout(function () { liberator.echomsg("Canceled playback of macro '" + this._lastMacro + "'"); }, 100); } } else diff --git a/common/content/finder.js b/common/content/finder.js index 6f7db18d..6b1cbee9 100644 --- a/common/content/finder.js +++ b/common/content/finder.js @@ -238,7 +238,7 @@ const Finder = Module("finder", { this._found = fastFind.find(this._searchString, this._linksOnly) != Ci.nsITypeAheadFind.FIND_NOTFOUND; if (!this._found) - setTimeout(function () liberator.echoerr("E486: Pattern not found: " + finder._searchPattern, commandline.FORCE_SINGLELINE), 0); + this.setTimeout(function () liberator.echoerr("E486: Pattern not found: " + this._searchPattern, commandline.FORCE_SINGLELINE), 0); }, /** @@ -325,7 +325,7 @@ const Finder = Module("finder", { // TODO: move to find() when reverse incremental searching is kludged in // need to find again for reverse searching if (this._backwards) - setTimeout(function () { finder.findAgain(false); }, 0); + this.setTimeout(function () { this.findAgain(false); }, 0); if (options["hlsearch"]) this.highlight(this._searchString); @@ -493,9 +493,9 @@ const RangeFinder = Module("rangefinder", { else if (this.rangeFind.wrapped) { // hack needed, because wrapping causes a "scroll" event which clears // our command line - setTimeout(function () { - let msg = rangfinder.rangeFind.backward ? "search hit TOP, continuing at BOTTOM" - : "search hit BOTTOM, continuing at TOP"; + this.setTimeout(function () { + let msg = this.rangeFind.backward ? "search hit TOP, continuing at BOTTOM" + : "search hit BOTTOM, continuing at TOP"; commandline.echo(msg, commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES); }, 0); } diff --git a/common/content/hints.js b/common/content/hints.js index 29561afc..0624793b 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -488,10 +488,10 @@ const Hints = Module("hints", { if (timeout == 0) // force a possible mode change, based on whether an input field has focus events.onFocusChange(); - setTimeout(function () { + this.setTimeout(function () { if (modes.extended & modes.HINTS) modes.reset(); - hints._hintMode.action(elem, elem.href || "", hints._extendedhintCount); + this._hintMode.action(elem, elem.href || "", hints._extendedhintCount); }, timeout); return true; }, @@ -507,7 +507,7 @@ const Hints = Module("hints", { if (this._hintNumber > 0 && this._hintNumber * 10 <= this._validHints.length) { let timeout = options["hinttimeout"]; if (timeout > 0) - this._activeTimeout = setTimeout(function () { hints._processHints(true); }, timeout); + this._activeTimeout = this.setTimeout(function () { this._processHints(true); }, timeout); } else // we have a unique hint this._processHints(true); diff --git a/common/content/statusline.js b/common/content/statusline.js index c0408cbe..dd44fbd7 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -174,7 +174,7 @@ const StatusLine = Module("statusline", { updateTabCount: function updateTabCount(delayed) { if (liberator.has("tabs")) { if (delayed) - return void setTimeout(function () statusline.updateTabCount(false), 0); + return void this.setTimeout(function () this.updateTabCount(false), 0); // update the ordinal which is used for numbered tabs if (options.get("guioptions").has("n", "N"))