diff options
| author | Phil Crosby | 2014-04-30 00:56:03 -0700 |
|---|---|---|
| committer | Phil Crosby | 2014-04-30 00:56:03 -0700 |
| commit | 4cfb7dd9e38c4d4e3c269952402b4d8161007e6f (patch) | |
| tree | 23148fcf08f482d9f81d28d5a6d9c7600c1260e6 | |
| parent | c79b35114270ada790a564e1794d042dadf07356 (diff) | |
| parent | 63f0b24d35176e6f72429e6c4ed15b9282c6e21b (diff) | |
| download | vimium-4cfb7dd9e38c4d4e3c269952402b4d8161007e6f.tar.bz2 | |
Merge remote-tracking branch 'mrmr1993/openLinkInFGTab'
Conflicts:
content_scripts/link_hints.coffee
| -rw-r--r-- | background_scripts/commands.coffee | 27 | ||||
| -rw-r--r-- | content_scripts/link_hints.coffee | 31 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 4 | ||||
| -rw-r--r-- | lib/keyboard_utils.coffee | 3 |
4 files changed, 36 insertions, 29 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 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 diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 70e52a6c..dcdd5518 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -109,8 +109,8 @@ 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, modifiers.altKey, + modifiers.shiftKey, modifiers.metaKey, 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) diff --git a/lib/keyboard_utils.coffee b/lib/keyboard_utils.coffee index df5bbbad..d2a843f9 100644 --- a/lib/keyboard_utils.coffee +++ b/lib/keyboard_utils.coffee @@ -1,6 +1,7 @@ KeyboardUtils = keyCodes: - { ESC: 27, backspace: 8, deleteKey: 46, enter: 13, space: 32, shiftKey: 16, f1: 112, f12: 123, tab: 9 } + { ESC: 27, backspace: 8, deleteKey: 46, enter: 13, space: 32, shiftKey: 16, ctrlKey: 17, f1: 112, + f12: 123, tab: 9 } keyNames: { 37: "left", 38: "up", 39: "right", 40: "down" } |
