aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorPhil Crosby2014-04-30 00:56:03 -0700
committerPhil Crosby2014-04-30 00:56:03 -0700
commit4cfb7dd9e38c4d4e3c269952402b4d8161007e6f (patch)
tree23148fcf08f482d9f81d28d5a6d9c7600c1260e6 /content_scripts
parentc79b35114270ada790a564e1794d042dadf07356 (diff)
parent63f0b24d35176e6f72429e6c4ed15b9282c6e21b (diff)
downloadvimium-4cfb7dd9e38c4d4e3c269952402b4d8161007e6f.tar.bz2
Merge remote-tracking branch 'mrmr1993/openLinkInFGTab'
Conflicts: content_scripts/link_hints.coffee
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/link_hints.coffee31
1 files changed, 18 insertions, 13 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 7a83ec0d..24314b26 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -9,7 +9,8 @@
# typing the text of the link itself.
#
OPEN_IN_CURRENT_TAB = {}
-OPEN_IN_NEW_TAB = {}
+OPEN_IN_NEW_BG_TAB = {}
+OPEN_IN_NEW_FG_TAB = {}
OPEN_WITH_QUEUE = {}
COPY_LINK_URL = {}
OPEN_INCOGNITO = {}
@@ -46,7 +47,8 @@ LinkHints =
"@contenteditable='' or translate(@contenteditable, 'TRUE', 'true')='true']"])
# We need this as a top-level function because our command system doesn't yet support arguments.
- activateModeToOpenInNewTab: -> @activateMode(OPEN_IN_NEW_TAB)
+ activateModeToOpenInNewTab: -> @activateMode(OPEN_IN_NEW_BG_TAB)
+ activateModeToOpenInNewForegroundTab: -> @activateMode(OPEN_IN_NEW_FG_TAB)
activateModeToCopyLinkUrl: -> @activateMode(COPY_LINK_URL)
activateModeWithQueue: -> @activateMode(OPEN_WITH_QUEUE)
activateModeToOpenIncognito: -> @activateMode(OPEN_INCOGNITO)
@@ -78,15 +80,18 @@ LinkHints =
})
setOpenLinkMode: (@mode) ->
- if @mode is OPEN_IN_NEW_TAB or @mode is OPEN_WITH_QUEUE
- if @mode is OPEN_IN_NEW_TAB
+ if @mode is OPEN_IN_NEW_BG_TAB or @mode is OPEN_IN_NEW_FG_TAB or @mode is OPEN_WITH_QUEUE
+ if @mode is OPEN_IN_NEW_BG_TAB
HUD.show("Open link in new tab")
+ else if @mode is OPEN_IN_NEW_FG_TAB
+ HUD.show("Open link in new tab and switch to it")
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
@@ -165,23 +170,23 @@ 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_BG_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)
+ if event.keyCode == keyCodes.shiftKey
+ @setOpenLinkMode(if @mode is OPEN_IN_CURRENT_TAB then OPEN_IN_NEW_BG_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_BG_TAB else OPEN_IN_NEW_FG_TAB)
# TODO(philc): Ignore keys that have modifiers.
if (KeyboardUtils.isEscape(event))
@deactivateMode()
- else if (event.keyCode != keyCodes.shiftKey)
+ else
keyResult = @getMarkerMatcher().matchHintsByKey(hintMarkers, event)
linksMatched = keyResult.linksMatched
delay = keyResult.delay ? 0