aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-02-16 11:57:29 +0000
committerStephen Blott2015-02-16 11:57:35 +0000
commit7cedc5d2481f61f4b0d1cbf99fbd203bb5c68b54 (patch)
tree598510660164a875e95226fb445d44ad05ba5884 /content_scripts
parent20c952fe6c4ede0fe7c3e90dbb5c88d3f4a7380c (diff)
downloadvimium-7cedc5d2481f61f4b0d1cbf99fbd203bb5c68b54.tar.bz2
Deactivate global insert mode on focus.
Rationale. There are really two insert modes: the one we activate with "i" and the one that's activated when a focusable element receives the focus. This makes that distinction clearer. And, in particular, it means that, when the latter type of insert mode is active, we *know* that gloabl insert mode is *not* active.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode.coffee7
-rw-r--r--content_scripts/vimium_frontend.coffee4
2 files changed, 10 insertions, 1 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 7877d97c..fa583a1c 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -86,6 +86,13 @@ class Mode
_name: "mode-#{@id}/exitOnClick"
"click": (event) => @alwaysContinueBubbling => @exit event
+ #If @options.exitOnFocus is truthy, then the mode will exit whenever a focusable element is activated.
+ if @options.exitOnFocus
+ @push
+ _name: "mode-#{@id}/exitOnFocus"
+ "focus": (event) => @alwaysContinueBubbling =>
+ @exit event if DomUtils.isFocusable event.target
+
# Some modes are singletons: there may be at most one instance active at any time. A mode is a singleton
# if @options.singleton is truthy. The value of @options.singleton should be the key which is intended to
# be unique. New instances deactivate existing instances with the same key.
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 5bad1148..609b6b40 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -338,7 +338,9 @@ extend window,
HUD.showForDuration("Yanked #{url}", 2000)
enterInsertMode: ->
- new InsertMode global: true
+ # If a focusable element receives the focus, then we exit and leave the permanently-installed insert-mode
+ # instance to take over.
+ new InsertMode global: true, exitOnFocus: true
enterVisualMode: ->
new VisualMode()