aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode.coffee14
-rw-r--r--content_scripts/vimium_frontend.coffee42
2 files changed, 32 insertions, 24 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index dd797c46..1c6cddb1 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -44,7 +44,7 @@ count = 0
class Mode
# If Mode.debug is true, then we generate a trace of modes being activated and deactivated on the console, along
# with a list of the currently active modes.
- debug: false
+ debug: true
@modes: []
# Constants; short, readable names for handlerStack event-handler return values.
@@ -205,10 +205,14 @@ class Mode
log: (args...) ->
console.log args...
+ # Return the name of the must-recently activated mode.
+ @top: ->
+ @modes[@modes.length-1]?.name
+
# BadgeMode is a pseudo mode for triggering badge updates on focus changes and state updates. It sits at the
# bottom of the handler stack, and so it receives state changes *after* all other modes, and can override the
# badge choice of the other active modes.
-# Note. We create the the one-and-only instance, here.
+# Note. We create the the one-and-only instance here.
new class BadgeMode extends Mode
constructor: () ->
super
@@ -223,16 +227,18 @@ new class BadgeMode extends Mode
"focus": => @alwaysContinueBubbling -> Mode.updateBadge()
chooseBadge: (badge) ->
- # If we're not enabled, then post an empty badge.
+ # If we're not enabled, then post an empty badge. BadgeMode is last, so this takes priority.
badge.badge = "" unless @enabled
+ # When the registerStateChange event bubbles to the bottom of the stack, all modes have been notified. So
+ # it's now time to update the badge.
registerStateChange: ->
Mode.updateBadge()
# KeySuppressor is a pseudo mode (near the bottom of the stack) which suppresses keyboard events tagged with
# the "vimium_suppress_event" property. This allows modes higher up in the stack to tag events for
# suppression, but only after verifying that no other mode (notably, normal mode) wants to handle the event.
-# Note. We create the the one-and-only instance, here.
+# Note. We create the the one-and-only instance here.
new class KeySuppressor extends Mode
constructor: ->
super
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index ed5844dc..09e19486 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -108,9 +108,9 @@ class NormalMode extends Mode
super
name: "normal"
badge: "N"
- keydown: onKeydown
- keypress: onKeypress
- keyup: onKeyup
+ keydown: (event) => onKeydown.call @, event
+ keypress: (event) => onKeypress.call @, event
+ keyup: (event) => onKeyup.call @, event
chooseBadge: (badge) ->
super badge
@@ -460,7 +460,7 @@ KeydownEvents =
#
# Note that some keys will only register keydown events and not keystroke events, e.g. ESC.
#
-
+# @/this, here, is the the normal-mode Mode object.
onKeypress = (event) ->
keyChar = ""
@@ -471,25 +471,26 @@ onKeypress = (event) ->
# Enter insert mode when the user enables the native find interface.
if (keyChar == "f" && KeyboardUtils.isPrimaryModifierKey(event))
enterInsertModeWithoutShowingIndicator()
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
if (keyChar)
if (findMode)
handleKeyCharForFindMode(keyChar)
DomUtils.suppressEvent(event)
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (!isInsertMode() && !findMode)
if (isPassKey keyChar)
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
if currentCompletionKeys.indexOf(keyChar) != -1 or isValidFirstKey(keyChar)
DomUtils.suppressEvent(event)
keyPort.postMessage({ keyChar:keyChar, frameId:frameId })
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
keyPort.postMessage({ keyChar:keyChar, frameId:frameId })
- return true
+ return @continueBubbling
+# @/this, here, is the the normal-mode Mode object.
onKeydown = (event) ->
keyChar = ""
@@ -529,37 +530,37 @@ onKeydown = (event) ->
exitInsertMode()
DomUtils.suppressEvent event
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (findMode)
if (KeyboardUtils.isEscape(event))
handleEscapeForFindMode()
DomUtils.suppressEvent event
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey)
handleDeleteForFindMode()
DomUtils.suppressEvent event
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (event.keyCode == keyCodes.enter)
handleEnterForFindMode()
DomUtils.suppressEvent event
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (!modifiers)
DomUtils.suppressPropagation(event)
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (isShowingHelpDialog && KeyboardUtils.isEscape(event))
hideHelpDialog()
DomUtils.suppressEvent event
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
else if (!isInsertMode() && !findMode)
if (keyChar)
@@ -567,7 +568,7 @@ onKeydown = (event) ->
DomUtils.suppressEvent event
KeydownEvents.push event
keyPort.postMessage({ keyChar:keyChar, frameId:frameId })
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
keyPort.postMessage({ keyChar:keyChar, frameId:frameId })
@@ -589,14 +590,15 @@ onKeydown = (event) ->
isValidFirstKey(KeyboardUtils.getKeyChar(event))))
DomUtils.suppressPropagation(event)
KeydownEvents.push event
- return handlerStack.stopBubblingAndTrue
+ return @stopBubblingAndTrue
- return true
+ return @continueBubbling
+# @/this, here, is the the normal-mode Mode object.
onKeyup = (event) ->
- return true unless KeydownEvents.pop event
+ return @continueBubbling unless KeydownEvents.pop event
DomUtils.suppressPropagation(event)
- handlerStack.stopBubblingAndTrue
+ @stopBubblingAndTrue
checkIfEnabledForUrl = ->
url = window.location.toString()