aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Baumstark2012-01-23 12:42:04 +0100
committerNiklas Baumstark2012-04-10 23:54:37 +0200
commit9890e1700f1348ac6284f185e296b8e4402ffa51 (patch)
tree97661ee6711422c59b806d2d2ac1438387568601
parent9c3ea936687fa08161fa9f57d90233cb3796ff0d (diff)
downloadvimium-9890e1700f1348ac6284f185e296b8e4402ffa51.tar.bz2
restructure fuzzy mode flow
-rw-r--r--commands.js10
-rw-r--r--fuzzyMode.js67
2 files changed, 50 insertions, 27 deletions
diff --git a/commands.js b/commands.js
index 1c19e26a..2cfd5cfa 100644
--- a/commands.js
+++ b/commands.js
@@ -144,8 +144,8 @@ function clearKeyMappingsAndSetDefaults() {
"b": "activateBookmarkFindMode",
"B": "activateBookmarkFindModeToOpenInNewTab",
- "o": "fuzzyMode.activate",
- "O": "fuzzyMode.activateNewTab",
+ "o": "fuzzyMode.activateAll",
+ "O": "fuzzyMode.activateAllNewTab",
"gf": "nextFrame",
};
@@ -214,8 +214,8 @@ var commandDescriptions = {
activateBookmarkFindMode: ["Open a bookmark in the current tab"],
activateBookmarkFindModeToOpenInNewTab: ["Open a bookmark in a new tab"],
- 'fuzzyMode.activate': ["Open URL, bookmark, history entry or a custom search (fuzzy)"],
- 'fuzzyMode.activateNewTab': ["Open URL, bookmark, history entry or a custom search (fuzzy, new tab)"],
+ 'fuzzyMode.activateAll': ["Open URL, bookmark, history entry or a custom search (fuzzy)"],
+ 'fuzzyMode.activateAllNewTab': ["Open URL, bookmark, history entry or a custom search (fuzzy, new tab)"],
nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }]
};
@@ -236,7 +236,7 @@ var commandGroups = {
"enterInsertMode", "focusInput",
"linkHints.activateMode", "linkHints.activateModeToOpenInNewTab", "linkHints.activateModeWithQueue",
"activateBookmarkFindMode", "activateBookmarkFindModeToOpenInNewTab",
- "fuzzyMode.activate", "fuzzyMode.activateNewTab",
+ "fuzzyMode.activateAll", "fuzzyMode.activateAllNewTab",
"goPrevious", "goNext", "nextFrame"],
findCommands: ["enterFindMode", "performFind", "performBackwardsFind"],
historyNavigation:
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); },
}
})();