aboutsummaryrefslogtreecommitdiffstats
path: root/fuzzyMode.js
diff options
context:
space:
mode:
authorNiklas Baumstark2012-01-23 12:42:04 +0100
committerNiklas Baumstark2012-04-10 23:54:37 +0200
commit9890e1700f1348ac6284f185e296b8e4402ffa51 (patch)
tree97661ee6711422c59b806d2d2ac1438387568601 /fuzzyMode.js
parent9c3ea936687fa08161fa9f57d90233cb3796ff0d (diff)
downloadvimium-9890e1700f1348ac6284f185e296b8e4402ffa51.tar.bz2
restructure fuzzy mode flow
Diffstat (limited to 'fuzzyMode.js')
-rw-r--r--fuzzyMode.js67
1 files changed, 45 insertions, 22 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js
index 90ba0aa4..b332d084 100644
--- a/fuzzyMode.js
+++ b/fuzzyMode.js
@@ -1,35 +1,58 @@
var fuzzyMode = (function() {
+ var fuzzyBox = null; // the dialog instance for this window
+ var completers = {}; // completer cache
+
+ function createCompleter(name) {
+ if (name === 'smart')
+ return new completion.SmartCompleter({
+ 'wiki ': [ 'Wikipedia (en)', 'http://en.wikipedia.org/wiki/%s' ],
+ 'luck ': [ 'Google Lucky (en)', 'http://www.google.com/search?q=%s&btnI=I%27m+Feeling+Lucky' ],
+ 'cc ' : [ 'dict.cc', 'http://www.dict.cc/?s=%s' ],
+ ';' : [ 'goto', '%s' ],
+ '?' : [ 'search', function(query) { return utils.createSearchUrl(query) } ],
+ });
+ else if (name === 'history')
+ return new completion.FuzzyHistoryCompleter(2000);
+ else if (name === 'bookmarks')
+ return new completion.FuzzyBookmarkCompleter();
+ else if (name === 'tabs')
+ return new completion.FuzzyTabCompleter();
+ else if (name === 'all')
+ return new completion.MergingCompleter([
+ getCompleter('smart'),
+ getCompleter('history'),
+ getCompleter('tabs'),
+ ]);
+ }
+ function getCompleter(name) {
+ if (!(name in completers))
+ completers[name] = createCompleter(name);
+ return completers[name];
+ }
+
/** Trigger the fuzzy mode dialog */
- var fuzzyBox = null;
- function start(newTab) {
- if (!fuzzyBox) {
- var completer = new completion.MergingCompleter([
- new completion.SmartCompleter({
- 'wiki ': [ 'Wikipedia (en)', 'http://en.wikipedia.org/wiki/%s' ],
- 'luck ': [ 'Google Lucky (en)', 'http://www.google.com/search?q=%s&btnI=I%27m+Feeling+Lucky' ],
- 'cc ' : [ 'dict.cc', 'http://www.dict.cc/?s=%s' ],
- ';' : [ 'goto', '%s' ],
- '?' : [ 'search', function(query) { return utils.createSearchUrl(query) } ],
- }),
- new completion.FuzzyHistoryCompleter(2000),
- new completion.FuzzyBookmarkCompleter(),
- new completion.FuzzyTabCompleter(),
- ]);
- completer.refresh();
- fuzzyBox = new FuzzyBox(completer, 10);
- }
+ function start(name, newTab) {
+ var completer = getCompleter(name);
+ if (!fuzzyBox)
+ fuzzyBox = new FuzzyBox(10);
+ completer.refresh();
+ fuzzyBox.setCompleter(completer);
fuzzyBox.show(newTab);
}
/** User interface for fuzzy completion */
- var FuzzyBox = function(completer, maxResults) {
+ var FuzzyBox = function(maxResults) {
this.prompt = '> ';
this.maxResults = maxResults || 10;
- this.completer = completer;
this.initDom();
this.reset();
}
FuzzyBox.prototype = {
+ setCompleter: function(completer) {
+ this.completer = completer;
+ this.reset();
+ },
+
show: function(reverseAction) {
this.reverseAction = reverseAction;
this.box.style.display = 'block';
@@ -168,8 +191,8 @@ var fuzzyMode = (function() {
// public interface
return {
- activate: function() { start(false); },
- activateNewTab: function() { start(true); },
+ activateAll: function() { start('all', false); },
+ activateAllNewTab: function() { start('all', true); },
}
})();