aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content_scripts/mode.coffee19
-rw-r--r--content_scripts/mode_find.coffee2
-rw-r--r--content_scripts/mode_insert.coffee2
-rw-r--r--content_scripts/mode_visual_edit.coffee11
-rw-r--r--content_scripts/vimium_frontend.coffee10
5 files changed, 25 insertions, 19 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 5a26b836..c2e70e91 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -91,14 +91,10 @@ class Mode
# be unique. New instances deactivate existing instances with the same key.
if @options.singleton
do =>
- key = @options.singleton
- Mode.singletons ||= []
- @onExit => Mode.singletons = Mode.singletons.filter (active) => active.key != key
- for active in Mode.singletons
- if active.key == key
- console.log "singleton, deactivating:", active.mode.id if @debug
- active.mode.exit()
- Mode.singletons.push key: key, mode: @
+ console.log @options.singleton
+ @deactivateSingleton @options.singleton
+ @onExit => Mode.singletons = Mode.singletons.filter (active) => active.key != @options.singleton
+ Mode.singletons.push key: @options.singleton, mode: @
console.log "singletons:", (Mode.singletons.map (active) -> active.mode.id)... if @debug
# If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys,
@@ -142,6 +138,13 @@ class Mode
Mode.updateBadge()
@modeIsActive = false
+ deactivateSingleton: (key) ->
+ Mode.singletons ||= []
+ for active in Mode.singletons
+ if active.key == key and active.mode.modeIsActive
+ console.log "singleton, deactivating:", active.mode.id if @debug
+ active.mode.exit()
+
# The badge is chosen by bubbling an "updateBadge" event down the handler stack allowing each mode the
# opportunity to choose a badge. This is overridden in sub-classes.
updateBadge: (badge) ->
diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee
index 33a7dc4f..c0b97b16 100644
--- a/content_scripts/mode_find.coffee
+++ b/content_scripts/mode_find.coffee
@@ -35,7 +35,7 @@ class PostFindMode extends SuppressPrintable
name: "post-find"
# We show a "?" badge, but only while an Escape activates insert mode.
badge: "?"
- # Important. PostFindMode shares a singleton with suspendedEditmode (see the exit() method of EditMode).
+ # Important. PostFindMode shares a singleton with the modes launched by focusInput.
singleton: element
exitOnBlur: element
exitOnClick: true
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index 79043be9..81a0e2ee 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -47,7 +47,7 @@ class InsertMode extends Mode
# We can't rely on focus and blur events arriving in the expected order. When the active element
# changes, we might get "focus" before "blur". We track the active element in @insertModeLock, and
# exit only when that element blurs.
- # We don't exit is we're running under edit mode. Edit mode itself will handles that case.
+ # We don't exit if we're running under edit mode. Edit mode itself will handles that case.
@exit event, target if @insertModeLock and target == @insertModeLock and not @options.editModeParent
"focus": (event) => @alwaysContinueBubbling =>
if @insertModeLock != event.target and DomUtils.isFocusable event.target
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee
index a1666d75..70d95dff 100644
--- a/content_scripts/mode_visual_edit.coffee
+++ b/content_scripts/mode_visual_edit.coffee
@@ -2,10 +2,11 @@
# Todo:
# Konami code?
# Use find as a mode.
-# Refactor visual/movement modes.
+# Perhaps refactor visual/movement modes.
+# FocusInput selector is currently broken.
# This prevents printable characters from being passed through to the underlying page. It should, however,
-# allow through chrome keyboard shortcuts. It's a keyboard-event backstop for visual mode and edit mode.
+# allow through Chrome keyboard shortcuts. It's a keyboard-event backstop for visual mode and edit mode.
class SuppressPrintable extends Mode
constructor: (options = {}) ->
handler = (event) =>
@@ -28,7 +29,7 @@ class SuppressPrintable extends Mode
keyup: handler
# This watches keyboard events and maintains @countPrefix as number keys and other keys are pressed.
-class MaintainCount extends SuppressPrintable
+class CountPrefix extends SuppressPrintable
constructor: (options) ->
super options
@@ -61,9 +62,9 @@ forward = "forward"
backward = "backward"
character = "character"
-# This implements movement commands with count prefixes (using MaintainCount) for both visual mode and edit
+# This implements movement commands with count prefixes (using CountPrefix) for both visual mode and edit
# mode.
-class Movement extends MaintainCount
+class Movement extends CountPrefix
opposite: forward: backward, backward: forward
copy: (text) ->
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 55237fe5..d1da9524 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -350,7 +350,7 @@ extend window,
# Focus the first input element on the page, and create overlays to highlight all the input elements, with
# the currently-focused element highlighted specially. Tabbing will shift focus to the next input element.
# Pressing any other key will remove the overlays and the special tab behavior.
- # If mode is provided, then enter that mode on exit. Otherwise, just let insert mode take over.
+ # The mode argument is the mode to enter once an input is selected.
resultSet = DomUtils.evaluateXPath textInputXPath, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE
visibleInputs =
for i in [0...resultSet.snapshotLength] by 1
@@ -386,9 +386,6 @@ extend window,
super
name: "focus-selector"
badge: "?"
- # We share a singleton with PostFindMode. That way, a new FocusSelector displaces any existing
- # PostFindMode.
- singleton: PostFindMode
exitOnClick: true
keydown: (event) =>
if event.keyCode == KeyboardUtils.keyCodes.tab
@@ -396,6 +393,8 @@ extend window,
selectedInputIndex += hints.length + (if event.shiftKey then -1 else 1)
selectedInputIndex %= hints.length
hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint'
+ # Deactivate any other modes on this element.
+ @deactivateSingleton visibleInputs[selectedInputIndex].element
visibleInputs[selectedInputIndex].element.focus()
@suppressEvent
else unless event.keyCode == KeyboardUtils.keyCodes.shiftKey
@@ -407,9 +406,12 @@ extend window,
id: "vimiumInputMarkerContainer"
className: "vimiumReset"
+ # Deactivate any other modes on this element.
+ @deactivateSingleton visibleInputs[selectedInputIndex].element
visibleInputs[selectedInputIndex].element.focus()
if visibleInputs.length == 1
@exit()
+ return
else
hints[selectedInputIndex].classList.add 'internalVimiumSelectedInputHint'