diff --git a/content/ui.js b/content/ui.js index b95435f6..7b6ef29f 100644 --- a/content/ui.js +++ b/content/ui.js @@ -564,7 +564,6 @@ liberator.CommandLine = function () //{{{ historyIndex = UNINITIALIZED; completionIndex = UNINITIALIZED; - autocompleteTimer.reset(); liberator.modes.push(liberator.modes.COMMAND_LINE, currentExtendedMode); setHighlightGroup(this.HL_NORMAL); @@ -812,7 +811,6 @@ liberator.CommandLine = function () //{{{ completions.sort(function (a, b) String.localeCompare(a[0], b[0])); completionList.setItems(completions); - statusTimer.reset(); } if (completions.length == 0) @@ -1234,8 +1232,15 @@ liberator.ItemList = function (id) //{{{ catch (e) {} // for muttator! // TODO: temporary, to be changed/removed - function createRow(a, b, c, dom) + function createRow(b, c, dom) { + try + { + let uri = ioService.newURI(b, null, null); + var a = faviconService.getFaviconImageForPage(uri).spec; + } + catch (e) {} + let row = @@ -1258,9 +1263,8 @@ liberator.ItemList = function (id) //{{{ if (completionElements.length == 0) return doc.height; - var wanted = maxItems + listOffset; - if (wanted > completionElements.length) - wanted = completionElements.length; + var wanted = Math.min(maxItems + listOffset, + completionElements.length); return completionElements[wanted - 1].getBoundingClientRect().bottom; } @@ -1285,38 +1289,25 @@ liberator.ItemList = function (id) //{{{ if (listIndex > -1 && offset == listOffset + 1) { listOffset = offset; - var icon = ""; - try - { - var uri = ioService.newURI(completions[offset][0], null, null); - icon = faviconService.getFaviconImageForPage(uri).spec; - } - catch (e) {} - - var row = createRow(icon, completions[offset + maxItems - 1][0], completions[offset + maxItems - 1][1], true); + var row = createRow(completions[offset + maxItems - 1][0], completions[offset + maxItems - 1][1], true); var e = doc.getElementsByTagName("tbody"); e = e[e.length - 1]; + e.removeChild(e.firstChild); e.appendChild(row); - completionElements = doc.getElementsByClassName("liberator-compitem"); // TODO: make faster + completionElements = e.children; return; } else if (listIndex > -1 && offset == listOffset - 1) { listOffset = offset; - var icon = ""; - try - { - var uri = ioService.newURI(completions[offset][0], null, null); - icon = faviconService.getFaviconImageForPage(uri).spec; - } - catch (e) {} - var row = createRow(icon, completions[offset][0], completions[offset][1], true); + var row = createRow(completions[offset][0], completions[offset][1], true); var e = doc.getElementsByTagName("tbody"); e = e[e.length - 1]; + e.removeChild(e.lastChild); e.insertBefore(row, e.firstChild); - completionElements = doc.getElementsByClassName("liberator-compitem"); // TODO: make faster + completionElements = e.children; return; } @@ -1331,21 +1322,12 @@ liberator.ItemList = function (id) //{{{ ; let tbody = div..tbody; - for (let [i, elem] in Iterator(completions)) + for (let i in liberator.util.range(offset, Math.min(offset + maxItems, + completions.length))) { - if (i >= listOffset && i - listOffset < maxItems) - { - let icon = ""; - try - { - let uri = ioService.newURI(elem[0], null, null); - icon = faviconService.getFaviconImageForPage(uri).spec; - } - catch (e) {} - - tbody.* += createRow(icon, elem[0], elem[1]); - } - }; + let elem = completions[i]; + tbody.* += createRow(elem[0], elem[1]); + } doc.body.appendChild(liberator.util.xmlToDom(div, doc)); diff --git a/content/util.js b/content/util.js index c183972f..dd8404d5 100644 --- a/content/util.js +++ b/content/util.js @@ -30,41 +30,38 @@ liberator.util = { //{{{ Timer: function Timer(minInterval, maxInterval, callback) { - let self = this; let timer = Components.classes["@mozilla.org/timer;1"] .createInstance(Components.interfaces.nsITimer); - this.first = true; /* When set, trigger immediately. */ + this.doneAt = 0; this.latest = 0; this.notify = function (aTimer) { timer.cancel(); - if (this.latest || this.first) - callback(this.arg); - else /* Don't trigger. Set this.first after the minimum interval. */ - timer.initWithCallback(this, minInterval, timer.TYPE_ONE_SHOT); - this.first = (this.latest == 0); + this.doneAt = Date.now() + minInterval; this.latest = 0; + callback(this.arg); } this.tell = function (arg) { - if (arg != undefined) + if (arg !== undefined) this.arg = arg; - if (this.first || this.latest > Date.now()) - return this.notify(); - if (this.latest) + if (this.doneAt == -1) timer.cancel(); + else if (Date.now() >= this.doneAt) + return this.notify(); let timeout = minInterval; if (this.latest) timeout = Math.min(minInterval, this.latest - Date.now()); else this.latest = Date.now() + maxInterval; - this.timer = timer.initWithCallback(this, timeout, timer.TYPE_ONE_SHOT); + timer.initWithCallback(this, timeout, timer.TYPE_ONE_SHOT); + this.doneAt = -1; } this.reset = function () { timer.cancel(); - this.first = true; + this.doneAt = 0; } this.flush = function () {