aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2018-08-13 13:26:54 +0100
committerStephen Blott2018-08-13 13:26:54 +0100
commitdf3eb554e934f2b7764dea064a90e0cee36d429e (patch)
tree134abf699941a13485a411a791026cf125809df0
parent43fe8cecdfb4f82f5d1d5f25520cd86a44824c67 (diff)
downloadvimium-df3eb554e934f2b7764dea064a90e0cee36d429e.tar.bz2
Cache keydown events while launching link hints.
Launching link hints can sometimes be slow. For filtered hints, the user already knows what to type - but must nevertheless wait until the hints have been calculated and rendered. Here, we cache intervening keydown events, and replay them once hints-mode proper is launched. This should make improve usability (in the case of filtered hints). Fixes #3050.
-rw-r--r--content_scripts/link_hints.coffee15
-rw-r--r--content_scripts/mode.coffee13
2 files changed, 21 insertions, 7 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 849aa4c5..86cc4e4f 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -52,7 +52,7 @@ availableModes = [OPEN_IN_CURRENT_TAB, OPEN_IN_NEW_BG_TAB, OPEN_IN_NEW_FG_TAB, O
HintCoordinator =
onExit: []
localHints: null
- suppressKeyboardEvents: null
+ cacheAllKeydownEvents: null
sendMessage: (messageType, request = {}) ->
Frame.postMessage "linkHintsMessage", extend request, {messageType}
@@ -60,15 +60,15 @@ HintCoordinator =
prepareToActivateMode: (mode, onExit) ->
# We need to communicate with the background page (and other frames) to initiate link-hints mode. To
# prevent other Vimium commands from being triggered before link-hints mode is launched, we install a
- # temporary mode to block keyboard events.
- @suppressKeyboardEvents = suppressKeyboardEvents = new SuppressAllKeyboardEvents
+ # temporary mode to block (and cache) keyboard events.
+ @cacheAllKeydownEvents = cacheAllKeydownEvents = new CacheAllKeydownEvents
name: "link-hints/suppress-keyboard-events"
singleton: "link-hints-mode"
indicator: "Collecting hints..."
exitOnEscape: true
# FIXME(smblott) Global link hints is currently insufficiently reliable. If the mode above is left in
# place, then Vimium blocks. As a temporary measure, we install a timer to remove it.
- Utils.setTimeout 1000, -> suppressKeyboardEvents.exit() if suppressKeyboardEvents?.modeIsActive
+ Utils.setTimeout 1000, -> cacheAllKeydownEvents.exit() if cacheAllKeydownEvents?.modeIsActive
@onExit = [onExit]
@sendMessage "prepareToActivateMode",
modeIndex: availableModes.indexOf(mode), isVimiumHelpDialog: window.isVimiumHelpDialog
@@ -103,10 +103,13 @@ HintCoordinator =
hintDescriptors = [].concat (hintDescriptors[fId] for fId in (fId for own fId of hintDescriptors).sort())...
# Ensure that the document is ready and that the settings are loaded.
DomUtils.documentReady => Settings.onLoaded =>
- @suppressKeyboardEvents.exit() if @suppressKeyboardEvents?.modeIsActive
- @suppressKeyboardEvents = null
+ @cacheAllKeydownEvents.exit() if @cacheAllKeydownEvents?.modeIsActive
@onExit = [] unless frameId == originatingFrameId
@linkHintsMode = new LinkHintsMode hintDescriptors, availableModes[modeIndex]
+ # Replay keydown events which we missed (but for filtered hints only).
+ @cacheAllKeydownEvents?.replayKeydownEvents() if Settings.get "filterLinkHints"
+ @cacheAllKeydownEvents = null
+ @linkHintsMode # Return this (for tests).
# The following messages are exchanged between frames while link-hints mode is active.
updateKeyState: (request) -> @linkHintsMode.updateKeyState request
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index a4a91c1f..8bdd6dd7 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -198,6 +198,17 @@ class SuppressAllKeyboardEvents extends Mode
suppressAllKeyboardEvents: true
super extend defaults, options
+class CacheAllKeydownEvents extends SuppressAllKeyboardEvents
+ constructor: (options = {}) ->
+ @keydownEvents = keydownEvents = []
+ defaults =
+ name: "cacheAllKeydownEvents"
+ keydown: (event) -> keydownEvents.push event
+ super extend defaults, options
+
+ replayKeydownEvents: ->
+ handlerStack.bubbleEvent "keydown", event for event in @keydownEvents
+
root = exports ? (window.root ?= {})
-extend root, {Mode, SuppressAllKeyboardEvents}
+extend root, {Mode, SuppressAllKeyboardEvents, CacheAllKeydownEvents}
extend window, root unless exports?