aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fuzzyMode.js29
-rw-r--r--lib/completion.js16
2 files changed, 19 insertions, 26 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js
index 31911c91..91fca8de 100644
--- a/fuzzyMode.js
+++ b/fuzzyMode.js
@@ -95,7 +95,7 @@ var fuzzyMode = (function() {
this.update(true, function() {
// Shift+Enter will open the result in a new tab instead of the current tab.
var openInNewTab = (event.shiftKey || isPrimaryModifierKey(event));
- self.completions[self.selection].action(openInNewTab);
+ self.completions[self.selection].performAction(openInNewTab);
self.hide();
});
}
@@ -170,9 +170,7 @@ var fuzzyMode = (function() {
* Sends filter and refresh requests to a Vomnibar completer on the background page.
*/
var BackgroundCompleter = Class.extend({
- /*
- * - name: The name of the background page completer that you want to interface with. One of [omni, tabs].
- */
+ /* - name: The background page completer that you want to interface with. Either "omni" or "tabs". */
init: function(name) {
this.name = name;
this.filterPort = chrome.extension.connect({ name: "filterCompleter" });
@@ -185,8 +183,8 @@ var fuzzyMode = (function() {
this.filterPort.onMessage.addListener(function(msg) {
if (msg.id != id) return;
callback(msg.results.map(function(result) {
- var action = result.action;
- result.action = eval(action.func).curry(action.args);
+ var functionToCall = eval(result.action.func);
+ result.performAction = functionToCall.curry(result.action.args);
return result;
}));
});
@@ -194,25 +192,20 @@ var fuzzyMode = (function() {
}
});
- /** Creates an action that opens :url in the current tab by default or in a new tab as an alternative. */
- function createActionOpenUrl(url, openInNewTab) {
- console.log("arguments:", arguments);
- // If the URL is a bookmarklet prefixed with javascript:, we don't need to open that in a new tab.
+ /* Called when an item in the Vomnibar is chosen and requires navigating to a URL. */
+ function navigateToUrl(url, openInNewTab) {
+ // If the URL is a bookmarklet prefixed with javascript:, we shouldn't open that in a new tab.
if (url.indexOf("javascript:") == 0)
openInNewTab = false;
- var selected = openInNewTab;
chrome.extension.sendRequest({
- handler: openInNewTab ? "openUrlInNewTab" : "openUrlInCurrentTab",
- url: url,
+ handler: openInNewTab ? "openUrlInNewTab" : "openUrlInCurrentTab",
+ url: url,
selected: openInNewTab
});
}
- /** Returns an action that switches to the tab with the given :id. */
- function createActionSwitchToTab(tabId) {
- chrome.extension.sendRequest({ handler: "selectSpecificTab", id: tabId });
- }
-
+ /* Called when an item in the Vomnibar is chosen and requires switching to a tab. */
+ function switchToTab(tabId) { chrome.extension.sendRequest({ handler: "selectSpecificTab", id: tabId }); }
// public interface
return {
diff --git a/lib/completion.js b/lib/completion.js
index b608a2e5..00ae526f 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -20,8 +20,8 @@ var completion = (function() {
createInternalMatch: function(type, item, action) {
var url = item.url;
var parts = [type, url, item.title];
- var str = parts.join(' ');
- action = action || {func: 'createActionOpenUrl', args: [url]};
+ var str = parts.join(" ");
+ action = action || { func: "navigateToUrl", args: [url] };
function createLazyCompletion(query) {
return new LazyCompletion(url.length / fuzzyMatcher.calculateRelevancy(query, str), function() {
@@ -87,7 +87,7 @@ var completion = (function() {
return new LazyCompletion(-2, function() {
return {
html: createCompletionHtml(desc, term),
- action: {func: 'createActionOpenUrl', args: [utils.createFullUrl(url)]},
+ action: { func: "navigateToUrl", args: [utils.createFullUrl(url)] },
}})
}.proxy(this));
},
@@ -101,8 +101,8 @@ var completion = (function() {
return new LazyCompletion(-1, function() {
return {
html: createCompletionHtml(isUrl ? "goto" : "search", query),
- action: {func: "createActionOpenUrl", args: isUrl ? [utils.createFullUrl(query)]
- : [utils.createSearchUrl(query)]},
+ action: { func: "navigateToUrl",
+ args: isUrl ? [utils.createFullUrl(query)] : [utils.createSearchUrl(query)] }
}});
},
@@ -175,7 +175,7 @@ var completion = (function() {
chrome.tabs.getAllInWindow(null, function(tabs) {
this.asyncCompleter.resultsReady(tabs.map(function(tab) {
return this.asyncCompleter.createInternalMatch("tab", tab,
- { func: "createActionSwitchToTab", args: [tab.id] });
+ { func: "switchToTab", args: [tab.id] });
}.proxy(this)));
}.proxy(this));
}
@@ -244,8 +244,8 @@ var completion = (function() {
bestOffset = offset;
best = new LazyCompletion(-1.5, function() {
return {
- html: createCompletionHtml('site', domain),
- action: {func: 'createActionOpenUrl', args: [protocol + '://' + domain]},
+ html: createCompletionHtml("site", domain),
+ action: { func: "navigateToUrl", args: [protocol + "://" + domain] },
}});
});
});