From 7cedc5d2481f61f4b0d1cbf99fbd203bb5c68b54 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 16 Feb 2015 11:57:29 +0000 Subject: 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. --- content_scripts/mode.coffee | 7 +++++++ content_scripts/vimium_frontend.coffee | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'content_scripts') 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() -- cgit v1.2.3