aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2009-12-05 20:36:12 -0800
committerPhil Crosby2009-12-05 20:36:12 -0800
commit277e6450be4917d875882946e1766d5f9a2e4b0f (patch)
treeb0af00ac1f119d22a3ed9d8aea09eb4eb6f31739
parent066ed27f2080fd0d4e7cb08559ac2183557b9f9a (diff)
downloadvimium-277e6450be4917d875882946e1766d5f9a2e4b0f.tar.bz2
Support shift+F to open a link in a background tab
-rw-r--r--background_page.html1
-rw-r--r--linkHints.js12
2 files changed, 11 insertions, 2 deletions
diff --git a/background_page.html b/background_page.html
index bc908481..6b957864 100644
--- a/background_page.html
+++ b/background_page.html
@@ -204,6 +204,7 @@
keyToCommandRegistry['zo'] = 'zoomOut';
keyToCommandRegistry['f'] = 'activateLinkHintsMode';
+ keyToCommandRegistry['F'] = 'activateLinkHintsModeToOpenInNewTab';
keyToCommandRegistry['/'] = 'enterFindMode';
keyToCommandRegistry['n'] = 'performFind';
diff --git a/linkHints.js b/linkHints.js
index 3f261d36..41fc93c3 100644
--- a/linkHints.js
+++ b/linkHints.js
@@ -24,6 +24,7 @@ var hintCharacters = "asdfjkl";
// The characters that were typed in while in "link hints" mode.
var hintKeystrokeQueue = [];
var linkHintsModeActivated = false;
+var shouldOpenLinkHintInNewTab = false;
// Whether we have added to the page the CSS needed to display link hints.
var linkHintsCssAdded = false;
@@ -31,10 +32,14 @@ var linkHintsCssAdded = false;
// attribute, but let's wait to see if that really is necessary.
var clickableElementsXPath = "//a | //textarea | //button | //select | //input[not(@type='hidden')]";
-function activateLinkHintsMode() {
+// We need this as a top-level function because our command system doesn't yet support arguments.
+function activateLinkHintsModeToOpenInNewTab() { activateLinkHintsMode(true); }
+
+function activateLinkHintsMode(openInNewTab) {
if (!linkHintsCssAdded)
addCssToPage(linkHintsCss);
linkHintsModeActivated = true;
+ shouldOpenLinkHintInNewTab = openInNewTab
buildLinkHints();
document.addEventListener("keydown", onKeyDownInLinkHintsMode, true);
}
@@ -209,7 +214,10 @@ function numberToHintString(number) {
function simulateClick(link) {
var event = document.createEvent("MouseEvents");
- event.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
+ // When "clicking" on a link, dispatch the event with the meta key on Mac to open it in a new tab.
+ // TODO(philc): We should dispatch this event with CTRL down on Windows and Linux.
+ event.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false,
+ shouldOpenLinkHintInNewTab, 0, null);
// Debugging note: Firefox will not execute the link's default action if we dispatch this click event,
// but Webkit will. Dispatching a click on an input box does not seem to focus it; we do that separately
link.dispatchEvent(event);