diff options
| author | Stephen Blott | 2016-02-09 16:51:20 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-02-18 07:34:30 +0000 | 
| commit | daa357f1a753fd4c17427f68e0f0c3338e9d668b (patch) | |
| tree | cda866637b9a944a254e967e351bf87c8a60a882 | |
| parent | 8e3ac1867b7577814865bf1cb40d0b865de30b1a (diff) | |
| download | vimium-daa357f1a753fd4c17427f68e0f0c3338e9d668b.tar.bz2 | |
PassNextKey; initial implementation.
This implements a passNextKey command (initially for normal mode only),
as discussed in #1955.
| -rw-r--r-- | background_scripts/commands.coffee | 5 | ||||
| -rw-r--r-- | content_scripts/mode_insert.coffee | 27 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 3 | 
3 files changed, 34 insertions, 1 deletions
| diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index db8cc60f..07f3640a 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -96,6 +96,7 @@ Commands =        "goUp",        "goToRoot",        "enterInsertMode", +      "passNextKey",        "enterVisualMode",        "enterVisualLineMode",        "focusInput", @@ -164,7 +165,8 @@ Commands =      "moveTabRight",      "closeTabsOnLeft",      "closeTabsOnRight", -    "closeOtherTabs"] +    "closeOtherTabs", +    "passNextKey"]  defaultKeyMappings =    "?": "showHelp" @@ -277,6 +279,7 @@ commandDescriptions =    openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true, repeatLimit: 20 }]    enterInsertMode: ["Enter insert mode", { noRepeat: true }] +  passNextKey: ["Pass the next key to Chrome", { passCountToFunction: true }]    enterVisualMode: ["Enter visual mode", { noRepeat: true }]    enterVisualLineMode: ["Enter visual line mode", { noRepeat: true }] diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index 0b040e5d..8dd02530 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -98,5 +98,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..01bd4ebc 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 | 
