aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrmr19932014-04-23 18:42:11 +0100
committermrmr19932014-04-23 19:31:19 +0100
commitce98782dc6881f2d8f53f7ea82b012564370cacd (patch)
tree41d42a443f9deef1bf0805b1ac4a26061e157631
parent719afdc68eda011d1f30ea8fb76f92c51609ade4 (diff)
downloadvimium-ce98782dc6881f2d8f53f7ea82b012564370cacd.tar.bz2
Add openlinks in foreground mode and fix #1035
-rw-r--r--background_scripts/commands.coffee27
-rw-r--r--content_scripts/link_hints.coffee38
-rw-r--r--lib/dom_utils.coffee5
3 files changed, 45 insertions, 25 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index ff98490c..807b8ec0 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -86,16 +86,15 @@ Commands =
# be shown in the help page.
commandGroups:
pageNavigation:
- ["scrollDown", "scrollUp", "scrollLeft", "scrollRight",
- "scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown",
- "scrollPageUp", "scrollFullPageUp", "scrollFullPageDown",
- "reload", "toggleViewSource", "copyCurrentUrl", "LinkHints.activateModeToCopyLinkUrl",
- "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", "goToRoot",
- "enterInsertMode", "focusInput",
- "LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab", "LinkHints.activateModeWithQueue",
- "Vomnibar.activate", "Vomnibar.activateInNewTab", "Vomnibar.activateTabSelection",
- "Vomnibar.activateBookmarks", "Vomnibar.activateBookmarksInNewTab",
- "goPrevious", "goNext", "nextFrame", "Marks.activateCreateMode", "Marks.activateGotoMode"]
+ ["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop", "scrollToBottom", "scrollToLeft",
+ "scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageUp", "scrollFullPageDown", "reload",
+ "toggleViewSource", "copyCurrentUrl", "LinkHints.activateModeToCopyLinkUrl",
+ "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", "goToRoot", "enterInsertMode",
+ "focusInput", "LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab",
+ "LinkHints.activateModeToOpenInNewForegroundTab", "LinkHints.activateModeWithQueue", "Vomnibar.activate",
+ "Vomnibar.activateInNewTab", "Vomnibar.activateTabSelection", "Vomnibar.activateBookmarks",
+ "Vomnibar.activateBookmarksInNewTab", "goPrevious", "goNext", "nextFrame", "Marks.activateCreateMode",
+ "Marks.activateGotoMode"]
findCommands: ["enterFindMode", "performFind", "performBackwardsFind"]
historyNavigation:
["goBack", "goForward"]
@@ -144,6 +143,7 @@ defaultKeyMappings =
"f": "LinkHints.activateMode"
"F": "LinkHints.activateModeToOpenInNewTab"
"<a-f>": "LinkHints.activateModeWithQueue"
+ "<c-F>": "LinkHints.activateModeToOpenInNewForegroundTab"
"/": "enterFindMode"
"n": "performFind"
@@ -217,9 +217,10 @@ commandDescriptions =
focusInput: ["Focus the first (or n-th) text box on the page", { passCountToFunction: true }]
- 'LinkHints.activateMode': ["Open a link in the current tab"]
- 'LinkHints.activateModeToOpenInNewTab': ["Open a link in a new tab"]
- 'LinkHints.activateModeWithQueue': ["Open multiple links in a new tab"]
+ "LinkHints.activateMode": ["Open a link in the current tab"]
+ "LinkHints.activateModeToOpenInNewTab": ["Open a link in a new tab"]
+ "LinkHints.activateModeToOpenInNewForegroundTab": ["Open a link in a new tab, switch to it"]
+ "LinkHints.activateModeWithQueue": ["Open multiple links in a new tab"]
"LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window"]
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index ca529b1f..16786966 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -10,6 +10,7 @@
#
OPEN_IN_CURRENT_TAB = {}
OPEN_IN_NEW_TAB = {}
+OPEN_IN_NEW_FG_TAB = {}
OPEN_WITH_QUEUE = {}
COPY_LINK_URL = {}
OPEN_INCOGNITO = {}
@@ -47,6 +48,7 @@ LinkHints =
# We need this as a top-level function because our command system doesn't yet support arguments.
activateModeToOpenInNewTab: -> @activateMode(OPEN_IN_NEW_TAB)
+ activateModeToOpenInNewForegroundTab: -> @activateMode(OPEN_IN_NEW_FG_TAB)
activateModeToCopyLinkUrl: -> @activateMode(COPY_LINK_URL)
activateModeWithQueue: -> @activateMode(OPEN_WITH_QUEUE)
activateModeToOpenIncognito: -> @activateMode(OPEN_INCOGNITO)
@@ -77,15 +79,18 @@ LinkHints =
})
setOpenLinkMode: (@mode) ->
- if @mode is OPEN_IN_NEW_TAB or @mode is OPEN_WITH_QUEUE
+ if @mode is OPEN_IN_NEW_TAB or @mode is OPEN_IN_NEW_FG_TAB or @mode is OPEN_WITH_QUEUE
if @mode is OPEN_IN_NEW_TAB
HUD.show("Open link in new tab")
+ else if @mode is OPEN_IN_NEW_FG_TAB
+ HUD.show("Open link in new foreground tab")
else
HUD.show("Open multiple links in a new tab")
@linkActivator = (link) ->
# When "clicking" on a link, dispatch the event with the appropriate meta key (CMD on Mac, CTRL on
# windows) to open it in a new tab if necessary.
DomUtils.simulateClick(link, {
+ shiftKey: @mode is OPEN_IN_NEW_FG_TAB,
metaKey: KeyboardUtils.platform == "Mac",
ctrlKey: KeyboardUtils.platform != "Mac" })
else if @mode is COPY_LINK_URL
@@ -166,18 +171,31 @@ LinkHints =
onKeyDownInMode: (hintMarkers, event) ->
return if @delayMode
- if (event.keyCode == keyCodes.shiftKey && @mode != COPY_LINK_URL)
+ if ((event.keyCode == keyCodes.shiftKey or event.keyCode == keyCodes.ctrlKey) and
+ (@mode == OPEN_IN_CURRENT_TAB or
+ @mode == OPEN_IN_NEW_TAB or
+ @mode == OPEN_IN_NEW_FG_TAB))
# Toggle whether to open link in a new or current tab.
prev_mode = @mode
- @setOpenLinkMode(if @mode is OPEN_IN_CURRENT_TAB then OPEN_IN_NEW_TAB else OPEN_IN_CURRENT_TAB)
-
- handlerStack.push({
- keyup: (event) =>
- return if (event.keyCode != keyCodes.shiftKey)
- @setOpenLinkMode(prev_mode) if @isActive
- handlerStack.remove()
- })
+ if event.keyCode == keyCodes.shiftKey
+ @setOpenLinkMode(if @mode is OPEN_IN_CURRENT_TAB then OPEN_IN_NEW_TAB else OPEN_IN_CURRENT_TAB)
+
+ handlerStack.push({
+ keyup: (event) =>
+ return if (event.keyCode != keyCodes.shiftKey)
+ @setOpenLinkMode(prev_mode) if @isActive
+ handlerStack.remove()
+ })
+ else # event.keyCode == keyCodes.ctrlKey
+ @setOpenLinkMode(if @mode is OPEN_IN_NEW_FG_TAB then OPEN_IN_NEW_TAB else OPEN_IN_NEW_FG_TAB_TAB)
+
+ handlerStack.push({
+ keyup: (event) =>
+ return if (event.keyCode != keyCodes.ctrlKey)
+ @setOpenLinkMode(prev_mode) if @isActive
+ handlerStack.remove()
+ })
# TODO(philc): Ignore keys that have modifiers.
if (KeyboardUtils.isEscape(event))
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 70e52a6c..9a006c2b 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -109,8 +109,9 @@ DomUtils =
eventSequence = ["mouseover", "mousedown", "mouseup", "click"]
for event in eventSequence
mouseEvent = document.createEvent("MouseEvents")
- mouseEvent.initMouseEvent(event, true, true, window, 1, 0, 0, 0, 0, modifiers.ctrlKey, false, false,
- modifiers.metaKey, 0, null)
+ mouseEvent.initMouseEvent(event, true, true, window, 1, 0, 0, 0, 0,
+ modifiers.ctrlKey == true, modifiers.altKey == true,
+ modifiers.shiftKey == true, modifiers.metaKey == true, 0, null)
# Debugging note: Firefox will not execute the element'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
element.dispatchEvent(mouseEvent)