aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-10-10 07:25:25 +0100
committerStephen Blott2015-10-10 07:25:25 +0100
commitad53ad0b0b9a75825caf796ff65e091deb784e84 (patch)
tree87901040ee50c89d34a71a052bf096a80b71014d
parent85e12c5006a11fec9790fc6725e8078ecdbc198f (diff)
parent69d03bbe5561d3f5a686dcaf8f75553bc7e2cb66 (diff)
downloadvimium-ad53ad0b0b9a75825caf796ff65e091deb784e84.tar.bz2
Merge pull request #1845 from smblott-github/better-delay-for-filtered-link-hints
Block keyboard events when a filtered hint matches.
-rw-r--r--content_scripts/link_hints.coffee27
-rw-r--r--manifest.json2
-rw-r--r--tests/dom_tests/dom_tests.html2
3 files changed, 23 insertions, 8 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index cdd2dfac..bf120629 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -34,8 +34,6 @@ class LinkHintsMode
mode: undefined
# Function that does the appropriate action on the selected link.
linkActivator: undefined
- # While in delayMode, all keypresses have no effect.
- delayMode: false
# Lock to ensure only one instance runs at a time.
isActive: false
# The link-hints "mode" (in the key-handler, indicator sense).
@@ -287,7 +285,7 @@ class LinkHintsMode
# Handles <Shift> and <Ctrl>.
onKeyDownInMode: (hintMarkers, event) ->
- return if @delayMode or event.repeat
+ return if event.repeat
@keydownKeyChar = KeyboardUtils.getKeyChar(event).toLowerCase()
previousTabCount = @tabCount
@@ -334,7 +332,7 @@ class LinkHintsMode
# Handles normal input.
onKeyPressInMode: (hintMarkers, event) ->
- return if @delayMode or event.repeat
+ return if event.repeat
keyChar = String.fromCharCode(event.charCode).toLowerCase()
if keyChar
@@ -359,7 +357,6 @@ class LinkHintsMode
# When only one link hint remains, this function activates it in the appropriate way.
#
activateLink: (matchedLink, delay = 0) ->
- @delayMode = true
clickEl = matchedLink.clickableItem
if (DomUtils.isSelectable(clickEl))
DomUtils.simulateSelect(clickEl)
@@ -401,7 +398,9 @@ class LinkHintsMode
@tabCount = 0
if delay
- Utils.setTimeout delay, ->
+ # Install a mode to block keyboard events if the user is still typing. The intention is to prevent the
+ # user from inadvertently launching Vimium commands when typing the link text.
+ new TypingProtector delay, ->
deactivate()
callback?()
else
@@ -657,6 +656,22 @@ numberToHintString = (number, characterSet, numHintDigits = 0) ->
hintString.join("")
+# Suppress all keyboard events until the user stops typing for sufficiently long.
+class TypingProtector extends Mode
+ constructor: (delay, callback) ->
+ @timer = Utils.setTimeout delay, => @exit()
+
+ handler = (event) =>
+ clearTimeout @timer
+ @timer = Utils.setTimeout 150, => @exit()
+
+ super
+ name: "hint/typing-protector"
+ suppressAllKeyboardEvents: true
+ keydown: handler
+ keypress: handler
+
+ @onExit callback
root = exports ? window
root.LinkHints = LinkHints
diff --git a/manifest.json b/manifest.json
index acd41d12..63d96e6f 100644
--- a/manifest.json
+++ b/manifest.json
@@ -42,12 +42,12 @@
"lib/handler_stack.js",
"lib/settings.js",
"lib/find_mode_history.js",
+ "content_scripts/mode.js",
"content_scripts/ui_component.js",
"content_scripts/link_hints.js",
"content_scripts/vomnibar.js",
"content_scripts/scroller.js",
"content_scripts/marks.js",
- "content_scripts/mode.js",
"content_scripts/mode_insert.js",
"content_scripts/mode_passkeys.js",
"content_scripts/mode_find.js",
diff --git a/tests/dom_tests/dom_tests.html b/tests/dom_tests/dom_tests.html
index 25c5f8ba..8d355c6d 100644
--- a/tests/dom_tests/dom_tests.html
+++ b/tests/dom_tests/dom_tests.html
@@ -37,11 +37,11 @@
<script type="text/javascript" src="../../lib/clipboard.js"></script>
<script type="text/javascript" src="../../lib/settings.js"></script>
<script type="text/javascript" src="../../lib/find_mode_history.js"></script>
+ <script type="text/javascript" src="../../content_scripts/mode.js"></script>
<script type="text/javascript" src="../../content_scripts/ui_component.js"></script>
<script type="text/javascript" src="../../content_scripts/link_hints.js"></script>
<script type="text/javascript" src="../../content_scripts/vomnibar.js"></script>
<script type="text/javascript" src="../../content_scripts/scroller.js"></script>
- <script type="text/javascript" src="../../content_scripts/mode.js"></script>
<script type="text/javascript" src="../../content_scripts/mode_passkeys.js"></script>
<script type="text/javascript" src="../../content_scripts/mode_insert.js"></script>
<script type="text/javascript" src="../../content_scripts/mode_find.js"></script>