aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2016-02-18 10:29:51 +0000
committerStephen Blott2016-02-18 10:29:51 +0000
commitf91fb7b9e11095cbb59174601096f0239501f6a0 (patch)
treed0ac44c1ee050c256e3e03de244a3b0efb50d02f /content_scripts
parent8e3ac1867b7577814865bf1cb40d0b865de30b1a (diff)
parent38509ce26afd1df7288255bfbcae1705f7bf9d86 (diff)
downloadvimium-f91fb7b9e11095cbb59174601096f0239501f6a0.tar.bz2
Merge pull request #1985 from smblott-github/pass-next-key
New command: Pass next key
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode_insert.coffee33
-rw-r--r--content_scripts/vimium_frontend.coffee51
2 files changed, 45 insertions, 39 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index 0b040e5d..a35633ac 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -10,6 +10,12 @@ class InsertMode extends Mode
handleKeyEvent = (event) =>
return @continueBubbling unless @isActive event
+
+ # Check for a pass-next-key key.
+ if KeyboardUtils.getKeyCharString(event) in Settings.get "passNextKeyKeys"
+ new PassNextKeyMode
+ return false
+
return @stopBubblingAndTrue unless event.type == 'keydown' and KeyboardUtils.isEscape event
DomUtils.suppressKeyupAfterEscape handlerStack
target = event.srcElement
@@ -98,5 +104,32 @@ class InsertMode extends Mode
@suppressedEvent: null
@suppressEvent: (event) -> @suppressedEvent = event
+# This implements the pasNexKey command.
+class PassNextKeyMode extends Mode
+ constructor: (count = 1) ->
+ seenKeyDown = false
+ keyDownCount = 0
+
+ super
+ name: "pass-next-key"
+ indicator: "Pass next key."
+ # We exit on blur because, once we lose the focus, we can no longer track key events.
+ exitOnBlur: window
+ keypress: =>
+ @stopBubblingAndTrue
+
+ keydown: =>
+ seenKeyDown = true
+ keyDownCount += 1
+ @stopBubblingAndTrue
+
+ keyup: =>
+ if seenKeyDown
+ unless 0 < --keyDownCount
+ unless 0 < --count
+ @exit()
+ @stopBubblingAndTrue
+
root = exports ? window
root.InsertMode = InsertMode
+root.PassNextKeyMode = PassNextKeyMode
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index f78b79b0..eb52e4ee 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -368,6 +368,9 @@ extend window,
enterVisualLineMode: ->
new VisualLineMode
+ passNextKey: (count) ->
+ new PassNextKeyMode count
+
focusInput: do ->
# Track the most recently focused input element.
recentlyFocusedElement = null
@@ -486,50 +489,20 @@ handlerStack.push
#
# @/this, here, is the the normal-mode Mode object.
onKeypress = (event) ->
- keyChar = ""
-
- # Ignore modifier keys by themselves.
- if (event.keyCode > 31)
- keyChar = String.fromCharCode(event.charCode)
+ keyChar = KeyboardUtils.getKeyCharString event
+ if keyChar
+ if currentCompletionKeys.indexOf(keyChar) != -1 or isValidFirstKey keyChar
+ DomUtils.suppressEvent(event)
+ keyPort.postMessage keyChar:keyChar, frameId:frameId
+ return @stopBubblingAndTrue
- if (keyChar)
- if currentCompletionKeys.indexOf(keyChar) != -1 or isValidFirstKey(keyChar)
- DomUtils.suppressEvent(event)
- keyPort.postMessage({ keyChar:keyChar, frameId:frameId })
- return @stopBubblingAndTrue
-
- keyPort.postMessage({ keyChar:keyChar, frameId:frameId })
+ keyPort.postMessage keyChar:keyChar, frameId:frameId
return @continueBubbling
# @/this, here, is the the normal-mode Mode object.
onKeydown = (event) ->
- keyChar = ""
-
- # handle special keys, and normal input keys with modifiers being pressed. don't handle shiftKey alone (to
- # avoid / being interpreted as ?
- if (((event.metaKey || event.ctrlKey || event.altKey) && event.keyCode > 31) || (
- # TODO(philc): some events don't have a keyidentifier. How is that possible?
- event.keyIdentifier && event.keyIdentifier.slice(0, 2) != "U+"))
- keyChar = KeyboardUtils.getKeyChar(event)
- # Again, ignore just modifiers. Maybe this should replace the keyCode>31 condition.
- if (keyChar != "")
- modifiers = []
-
- if (event.shiftKey)
- keyChar = keyChar.toUpperCase()
- if (event.metaKey)
- modifiers.push("m")
- if (event.ctrlKey)
- modifiers.push("c")
- if (event.altKey)
- modifiers.push("a")
-
- for own i of modifiers
- keyChar = modifiers[i] + "-" + keyChar
-
- if (modifiers.length > 0 || keyChar.length > 1)
- keyChar = "<" + keyChar + ">"
+ keyChar = KeyboardUtils.getKeyCharString event
if (HelpDialog.showing && KeyboardUtils.isEscape(event))
HelpDialog.hide()
@@ -557,7 +530,7 @@ onKeydown = (event) ->
# Subject to internationalization issues since we're using keyIdentifier instead of charCode (in keypress).
#
# TOOD(ilya): Revisit this. Not sure it's the absolute best approach.
- if keyChar == "" &&
+ if not keyChar &&
(currentCompletionKeys.indexOf(KeyboardUtils.getKeyChar(event)) != -1 ||
isValidFirstKey(KeyboardUtils.getKeyChar(event)))
DomUtils.suppressPropagation(event)