diff options
| author | Stephen Blott | 2016-02-01 06:27:37 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-02-01 06:27:37 +0000 |
| commit | fc9ac71d78ecfb2dd33baa649e8971a98518f943 (patch) | |
| tree | 345ec0a8d72cfa6891c221824e01a37143817cf9 /content_scripts/link_hints.coffee | |
| parent | 8fdc87e4079975cf2a31fc4b60afb897262c525c (diff) | |
| parent | b5cb14171b3dbd48ebb213654f2758781d7f127c (diff) | |
| download | vimium-fc9ac71d78ecfb2dd33baa649e8971a98518f943.tar.bz2 | |
Merge pull request #1963 from smblott-github/link-hints-with-count
Link hints with count
Diffstat (limited to 'content_scripts/link_hints.coffee')
| -rw-r--r-- | content_scripts/link_hints.coffee | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 54476935..6f95ac57 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -19,14 +19,21 @@ OPEN_INCOGNITO = name: "incognito" DOWNLOAD_LINK_URL = name: "download" LinkHints = - activateMode: (mode = OPEN_IN_CURRENT_TAB) -> new LinkHintsMode mode - - 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 - activateModeToDownloadLink: -> @activateMode DOWNLOAD_LINK_URL + activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> + if 0 < count + new LinkHintsMode mode, (event = null) -> + # This is called which LinkHintsMode exits. Escape and Backspace are the two ways in which hints mode + # can exit following which we do not restart hints mode. + return if event?.type == "keydown" and KeyboardUtils.isEscape event + return if event?.type == "keydown" and event.keyCode in [ keyCodes.backspace, keyCodes.deleteKey ] + LinkHints.activateMode count-1, mode + + activateModeToOpenInNewTab: (count) -> @activateMode count, OPEN_IN_NEW_BG_TAB + activateModeToOpenInNewForegroundTab: (count) -> @activateMode count, OPEN_IN_NEW_FG_TAB + activateModeToCopyLinkUrl: (count) -> @activateMode count, COPY_LINK_URL + activateModeWithQueue: -> @activateMode 1, OPEN_WITH_QUEUE + activateModeToOpenIncognito: (count) -> @activateMode count, OPEN_INCOGNITO + activateModeToDownloadLink: (count) -> @activateMode count, DOWNLOAD_LINK_URL class LinkHintsMode hintMarkerContainingDiv: null @@ -43,7 +50,7 @@ class LinkHintsMode # A count of the number of Tab presses since the last non-Tab keyboard event. tabCount: 0 - constructor: (mode = OPEN_IN_CURRENT_TAB) -> + constructor: (mode = OPEN_IN_CURRENT_TAB, onExit = (->)) -> # we need documentElement to be ready in order to append links return unless document.documentElement @isActive = true @@ -80,6 +87,7 @@ class LinkHintsMode @hintMode.onExit => @deactivateMode() if @isActive + @hintMode.onExit onExit @setOpenLinkMode mode @@ -323,7 +331,9 @@ class LinkHintsMode if @markerMatcher.popKeyChar() @updateVisibleMarkers hintMarkers else - @deactivateMode() + # Exit via @hintMode.exit(), so that the LinkHints.activate() "onExit" callback sees the key event and + # knows not to restart hints mode. + @hintMode.exit event else if event.keyCode == keyCodes.enter # Activate the active hint, if there is one. Only FilterHints uses an active hint. |
