aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2012-05-05 15:57:56 -0700
committerPhil Crosby2012-05-05 18:32:14 -0700
commit00cdb82cdd025a8d246073330d9970563d1676cb (patch)
tree1f70efd89312ec553676c4a4c5f24c7ff383357a
parent5f946f23d453bcde40a0de2dc7f83db3fb0bf723 (diff)
downloadvimium-00cdb82cdd025a8d246073330d9970563d1676cb.tar.bz2
Simplify the strange contract of createActionOpenUrl
-rw-r--r--fuzzyMode.js35
1 files changed, 14 insertions, 21 deletions
diff --git a/fuzzyMode.js b/fuzzyMode.js
index f7514276..f4bc2357 100644
--- a/fuzzyMode.js
+++ b/fuzzyMode.js
@@ -91,12 +91,11 @@ var fuzzyMode = (function() {
this.update(true); // force immediate update
}
- // use primary action with Enter. Holding down Shift/Ctrl uses the alternative action
- // (opening in new tab)
else if (event.keyCode == keyCodes.enter) {
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 ? 1 : 0]();
+ self.completions[self.selection].action(openInNewTab);
self.hide();
});
}
@@ -197,28 +196,22 @@ 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) {
- var open = function(newTab, selected) {
- return function() {
- chrome.extension.sendRequest({
- handler: newTab ? "openUrlInNewTab" : "openUrlInCurrentTab",
- url: url,
- selected: selected
- });
- }
- }
-
- if (url.indexOf("javascript:") == 0)
- return [ open(false), open(false), open(false) ];
- else
- return [ open(false), open(true, true), open(true, false) ];
+ return function(openInNewTab) {
+ // If the URL is a bookmarklet prefixed with javascript:, we don't need to 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,
+ selected: openInNewTab
+ });
+ };
}
/** Returns an action that switches to the tab with the given :id. */
function createActionSwitchToTab(id) {
- var open = function() {
- chrome.extension.sendRequest({ handler: 'selectSpecificTab', id: id });
- }
- return [open, open, open];
+ return function() { chrome.extension.sendRequest({ handler: "selectSpecificTab", id: id }); };
}