From aad03c6d834d81d52c99d62f77fa87d0e5b3384f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 31 Jan 2016 15:26:46 +0000 Subject: Use a count with link hints. Pass a count to link-hint commands, and the link-hint mode is started that many times (except "with queue"). This resolves the same issue as #1291. However, this: - does not require re-basing (which is no biggie), and - keeps all of the count-handling logic (apart from plumbing) in one place, in `LinkHints.activateMode()`. The link-hints mode itself does not know anything about count handling. Serious bug: - Using `Escape` to exit does not cancel the repeat! Fixes #1289. Closes #1291. --- content_scripts/link_hints.coffee | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'content_scripts/link_hints.coffee') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 54476935..3fcbfd40 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -19,14 +19,16 @@ OPEN_INCOGNITO = name: "incognito" DOWNLOAD_LINK_URL = name: "download" LinkHints = - activateMode: (mode = OPEN_IN_CURRENT_TAB) -> new LinkHintsMode mode + activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> + if 0 < count + new LinkHintsMode mode, -> LinkHints.activateMode count-1, 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 + 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 +45,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 +82,7 @@ class LinkHintsMode @hintMode.onExit => @deactivateMode() if @isActive + @hintMode.onExit onExit @setOpenLinkMode mode -- cgit v1.2.3 From d3f83fbe03d80d77f20d364f7b5e6e52260f516f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 31 Jan 2016 17:04:52 +0000 Subject: Use a count with link hints; working w/ Escape. With a count, link hints now exit on `Escape`. --- content_scripts/link_hints.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'content_scripts/link_hints.coffee') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 3fcbfd40..b5fc974f 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -21,7 +21,9 @@ DOWNLOAD_LINK_URL = name: "download" LinkHints = activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> if 0 < count - new LinkHintsMode mode, -> LinkHints.activateMode count-1, mode + new LinkHintsMode mode, (event = null) -> + unless event?.type == "keydown" and KeyboardUtils.isEscape event + LinkHints.activateMode count-1, mode activateModeToOpenInNewTab: (count) -> @activateMode count, OPEN_IN_NEW_BG_TAB activateModeToOpenInNewForegroundTab: (count) -> @activateMode count, OPEN_IN_NEW_FG_TAB -- cgit v1.2.3 From da006481be45d58972982aac44d372450204e6fa Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 1 Feb 2016 05:57:27 +0000 Subject: Use a count with link hints; exit on Backspace. Normally, `Backspace` exits hints mode. It should exit hint mode with a count too. --- content_scripts/link_hints.coffee | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'content_scripts/link_hints.coffee') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index b5fc974f..dba55c9d 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -22,8 +22,11 @@ LinkHints = activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> if 0 < count new LinkHintsMode mode, (event = null) -> - unless event?.type == "keydown" and KeyboardUtils.isEscape event - LinkHints.activateMode count-1, mode + # Escape and Backspace are the two ways in which hints mode can exit following which we do no 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 @@ -328,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. -- cgit v1.2.3 From b5cb14171b3dbd48ebb213654f2758781d7f127c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 1 Feb 2016 06:24:17 +0000 Subject: Use a count with link hints; better comment. --- content_scripts/link_hints.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'content_scripts/link_hints.coffee') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index dba55c9d..6f95ac57 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -22,8 +22,8 @@ LinkHints = activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> if 0 < count new LinkHintsMode mode, (event = null) -> - # Escape and Backspace are the two ways in which hints mode can exit following which we do no restart - # hints mode. + # 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 -- cgit v1.2.3