1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-03 13:25:45 +01:00

Add Classeditor.jssetTimeout. Fix some broken timeouts.

This commit is contained in:
Kris Maglione
2009-11-11 19:18:04 -05:00
parent 5523b04604
commit b607764012
6 changed files with 28 additions and 32 deletions

View File

@@ -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", {

View File

@@ -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),

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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"))