diff options
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode_insert.coffee | 28 | ||||
| -rw-r--r-- | content_scripts/mode_passkeys.coffee | 7 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 32 |
3 files changed, 32 insertions, 35 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index f37cf1ad..9504edfd 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -31,6 +31,17 @@ class InsertMode extends Mode @activate() if document.activeElement?.isContentEditable @isInsertMode + activate: -> + unless @isInsertMode + @isInsertMode = true + @badge = "I" + Mode.updateBadge() + + deactivate: -> + @isInsertMode = false + @badge = "" + Mode.updateBadge() + generateKeyHandler: (type) -> (event) => return Mode.propagate unless @isActive() @@ -43,24 +54,12 @@ class InsertMode extends Mode # right thing to do for most common use cases. However, it could also cripple flash-based sites and # games. See discussion in #1211 and #1194. event.srcElement.blur() - @isInsertMode = false - Mode.updateBadge() + @deactivate() Mode.suppressPropagation - activate: -> - unless @isInsertMode - @isInsertMode = true - Mode.updateBadge() - - # Override updateBadgeForMode() from Mode.updateBadgeForMode(). - updateBadgeForMode: (badge) -> - handlerStack.alwaysPropagate => - super badge if @isActive() - constructor: -> super name: "insert" - badge: "I" keydown: @generateKeyHandler "keydown" keypress: @generateKeyHandler "keypress" keyup: @generateKeyHandler "keyup" @@ -73,8 +72,7 @@ class InsertMode extends Mode blur: (event) => handlerStack.alwaysPropagate => if @isInsertMode and @isFocusable event.target - @isInsertMode = false - Mode.updateBadge() + @deactivate() # We may already have been dropped into insert mode. So check. Mode.updateBadge() diff --git a/content_scripts/mode_passkeys.coffee b/content_scripts/mode_passkeys.coffee index bb4518ae..a953deca 100644 --- a/content_scripts/mode_passkeys.coffee +++ b/content_scripts/mode_passkeys.coffee @@ -28,20 +28,15 @@ class PassKeysMode extends Mode @passKeys = (request.enabled and request.passKeys) or "" if request.keyQueue? @keyQueue = request.keyQueue + @badge = if @passKeys and not @keyQueue then "P" else "" Mode.updateBadge() constructor: -> super name: "passkeys" - badge: "P" keydown: (event) => @handlePassKeyEvent event keypress: (event) => @handlePassKeyEvent event keyup: -> Mode.propagate - # Overriding updateBadgeForMode() from Mode.updateBadgeForMode(). - updateBadgeForMode: (badge) -> - handlerStack.alwaysPropagate => - super badge if @passKeys and not @keyQueue - root = exports ? window root.PassKeysMode = PassKeysMode diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index fb6199bf..2df2e226 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -106,6 +106,21 @@ frameId = Math.floor(Math.random()*999999999) hasModifiersRegex = /^<([amc]-)+.>/ +class NormalMode extends Mode + constructor: -> + super + name: "normal" + badge: "N" + keydown: onKeydown + keypress: onKeypress + keyup: onKeyup + + updateBadgeForMode: (badge) -> + handlerStack.alwaysPropagate => + # Idea... Instead of an icon, we could show the keyQueue here (if it's non-empty). + super badge + badge.badge = "" unless isEnabledForUrl + # # Complete initialization work that sould be done prior to DOMReady. # @@ -115,20 +130,9 @@ initializePreDomReady = -> # Install normal mode. This is at the bottom of both the mode stack and the handler stack, and is never # deactivated. - new Mode - name: "normal" - badge: "N" - keydown: onKeydown - keypress: onKeypress - keyup: onKeyup - - # Overriding updateBadgeForMode() from Mode.updateBadgeForMode(). - updateBadgeForMode: (badge) -> - handlerStack.alwaysPropagate => - badge.badge ||= if keyQueue then keyQueue else @badge - badge.badge = "" unless isEnabledForUrl - - # Initialize the scroller. The scroller install a key handler, and this is next on the handler stack, + new NormalMode() + + # Initialize the scroller. The scroller installs a key handler, and this is next on the handler stack, # immediately above normal mode. Scroller.init settings |
