aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-14 15:15:40 +0000
committerStephen Blott2015-01-14 16:17:18 +0000
commitb594caa3eb792dfeb9d423c81a5136102a013b0a (patch)
tree9b00f18f86d0f94d744cf8cb863ddfa07d249786
parentab56d8bcd6686991483694d7153c4d0c9b5e513a (diff)
downloadvimium-b594caa3eb792dfeb9d423c81a5136102a013b0a.tar.bz2
Modes; more reworking.
-rw-r--r--content_scripts/mode.coffee6
-rw-r--r--content_scripts/mode_insert.coffee33
-rw-r--r--content_scripts/vimium_frontend.coffee8
3 files changed, 26 insertions, 21 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index ab482e8f..79559e35 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.
@@ -86,7 +86,7 @@ class Mode
_name: "mode-#{@id}/exitOnEscape"
"keydown": (event) =>
return @continueBubbling unless KeyboardUtils.isEscape event
- @exit event
+ @exit event, event.srcElement
DomUtils.suppressKeyupAfterEscape handlerStack
@suppressEvent
@@ -117,8 +117,8 @@ class Mode
@passKeys = passKeys
@registerStateChange?()
- Mode.updateBadge() if @badge
Mode.modes.push @
+ Mode.updateBadge()
@logStack() if @debug
# End of Mode constructor.
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index 135df0d0..d26f2568 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -1,10 +1,12 @@
class InsertMode extends Mode
- # There is one permanently-installed instance of InsertMode. This allows PostFindMode to query its state.
+ # There is one permanently-installed instance of InsertMode. This allows PostFindMode to query the active
+ # element.
@permanentInstance: null
constructor: (options = {}) ->
InsertMode.permanentInstance ||= @
+ @global = options.global
defaults =
name: "insert"
@@ -18,7 +20,7 @@ class InsertMode extends Mode
@push
"blur": (event) => @alwaysContinueBubbling =>
if DomUtils.isFocusable event.target
- @exit event.target
+ @exit event, event.target
Mode.updateBadge()
"focus": (event) => @alwaysContinueBubbling =>
@insertModeLock = event.target if DomUtils.isFocusable event.target
@@ -28,7 +30,7 @@ class InsertMode extends Mode
@insertModeLock = event.target if document.activeElement and DomUtils.isFocusable document.activeElement
isActive: ->
- return true if @insertModeLock != null
+ return true if @insertModeLock != null or @global
# Some sites (e.g. inbox.google.com) change the contentEditable property on the fly (see #1245); and
# unfortunately, the focus event fires *before* the change. Therefore, we need to re-check whether the
# active element is contentEditable.
@@ -39,14 +41,7 @@ class InsertMode extends Mode
return @continueBubbling if event == InsertMode.suppressedEvent or not @isActive()
return @stopBubblingAndTrue unless KeyboardUtils.isEscape event
DomUtils.suppressKeyupAfterEscape handlerStack
- if DomUtils.isFocusable event.srcElement
- # Remove focus so the user can't just get himself back into insert mode by typing in the same input
- # box.
- # NOTE(smblott, 2014/12/22) Including embeds for .blur() etc. here is experimental. It appears to be
- # the 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()
- @exit()
+ @exit event, event.srcElement
Mode.updateBadge()
@suppressEvent
@@ -54,10 +49,18 @@ class InsertMode extends Mode
handleKeyEvent: (event) ->
if @isActive() and event != InsertMode.suppressedEvent then @stopBubblingAndTrue else @continueBubbling
- exit: (target) ->
- if target == undefined or target == @insertModeLock
- # If this is the permanently-installed instance, then we don't actually exit; instead, we just reset.
- if @ == InsertMode.permanentInstance then @insertModeLock = null else super()
+ exit: (_, target) ->
+ if target and (target == @insertModeLock or @global) and DomUtils.isFocusable target
+ # Remove focus so the user can't just get himself back into insert mode by typing in the same input
+ # box.
+ # NOTE(smblott, 2014/12/22) Including embeds for .blur() etc. here is experimental. It appears to be
+ # the 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.
+ target.blur()
+ if target == undefined or target == @insertModeLock or @global
+ @insertModeLock = null
+ # Now really exit, unless this is the permanently-installed instance.
+ super() unless @ == InsertMode.permanentInstance
chooseBadge: (badge) ->
badge.badge ||= "I" if @isActive()
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index e14813f7..3dc8b93d 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -6,7 +6,6 @@
#
passKeysMode = null
-insertMode = null
targetElement = null
findMode = false
findModeQuery = { rawQuery: "", matchCount: 0 }
@@ -128,7 +127,7 @@ initializePreDomReady = ->
new NormalMode()
Scroller.init settings
passKeysMode = new PassKeysMode()
- insertMode = new InsertMode()
+ new InsertMode()
checkIfEnabledForUrl()
@@ -332,7 +331,8 @@ extend window,
HUD.showForDuration("Yanked URL", 1000)
enterInsertMode: ->
- new InsertMode()
+ new InsertMode
+ global: true
enterVisualMode: =>
new VisualMode()
@@ -394,6 +394,8 @@ extend window,
exit: ->
DomUtils.removeElement hintContainingDiv
super()
+ new InsertMode
+ targetElement: visibleInputs[selectedInputIndex].element
# Decide whether this keyChar should be passed to the underlying page.
# Keystrokes are *never* considered passKeys if the keyQueue is not empty. So, for example, if 't' is a