diff options
| author | Niklas Baumstark | 2012-01-25 00:22:38 +0100 |
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:54:39 +0200 |
| commit | 951a8535ced42904e97c88b97e98d303bf3672c2 (patch) | |
| tree | 4369687691d82e0b659eb2665085b9b4aa19bbbe | |
| parent | 3f1fa91d82c88e58273e4010f9b6dabc84088805 (diff) | |
| download | vimium-951a8535ced42904e97c88b97e98d303bf3672c2.tar.bz2 | |
code cleanup
| -rw-r--r-- | fuzzyMode.js | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js index 001bcb32..67a5e7d2 100644 --- a/fuzzyMode.js +++ b/fuzzyMode.js @@ -80,10 +80,9 @@ var fuzzyMode = (function() { }, updateSelection: function() { - var items = this.completionList.childNodes; - for (var i = 0; i < items.length; ++i) { - items[i].className = (i == this.selection) ? 'selected' : ''; - } + this.completionList.childNodes.forEach(function(child, i) { + child.className = (i == this.selection) ? 'selected' : ''; + }); }, onKeydown: function(event) { @@ -135,7 +134,6 @@ var fuzzyMode = (function() { else if (keyChar.length == 1) { this.query += keyChar; - this.update(); } @@ -157,19 +155,14 @@ var fuzzyMode = (function() { var self = this; this.completer.filter(this.query, function(completions) { + self.completions = completions.slice(0, self.maxResults); + // clear completions - self.completions = []; - while (self.completionList.hasChildNodes()) - self.completionList.removeChild(self.completionList.firstChild); - - for (var i = 0; i < completions.length && i < self.maxResults; ++i) { - self.completions.push(completions[i]); - var li = document.createElement('li'); - li.innerHTML = completions[i].render(); - self.completionList.appendChild(li); - } + self.completionList.innerHTML = self.completions.map(function(completion) { + return '<li>' + completion.render() + '</li>'; + }).join(''); - self.completionList.style.display = completions.length > 0 ? 'block' : 'none'; + self.completionList.style.display = self.completions.length > 0 ? 'block' : 'none'; self.updateSelection(); }); }, |
