aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content_scripts/mode_insert.coffee49
1 files changed, 25 insertions, 24 deletions
diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee
index ccd93870..34fad926 100644
--- a/content_scripts/mode_insert.coffee
+++ b/content_scripts/mode_insert.coffee
@@ -1,6 +1,7 @@
class InsertMode extends Mode
isInsertMode: false
+ insertModeLock: null
# Input or text elements are considered focusable and able to receieve their own keyboard events, and will
# enter insert mode if focused. Also note that the "contentEditable" attribute can be set on any element
@@ -31,47 +32,47 @@ class InsertMode extends Mode
@activate() if document.activeElement?.isContentEditable
@isInsertMode
- activate: ->
+ activate: (target=null) ->
unless @isInsertMode
@isInsertMode = true
+ @insertModeLock = target
@badge = "I"
Mode.updateBadge()
deactivate: ->
- @isInsertMode = false
- @badge = ""
- Mode.updateBadge()
-
- generateKeyHandler: (type) ->
- (event) =>
- return @continueBubbling unless @isActive()
- return @stopBubblingAndTrue unless type == "keydown" and KeyboardUtils.isEscape event
- # We're now exiting insert mode.
- if @isEditable(event.srcElement) or @isEmbed event.srcElement
- # Remove the 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() 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()
- @deactivate()
- @suppressEvent
+ if @isInsertMode
+ @isInsertMode = false
+ @insertModeLock = null
+ @badge = ""
+ Mode.updateBadge()
constructor: ->
super
name: "insert"
- keydown: @generateKeyHandler "keydown"
- keypress: @generateKeyHandler "keypress"
- keyup: @generateKeyHandler "keyup"
+ keydown: (event) =>
+ return @continueBubbling unless @isActive()
+ return @stopBubblingAndTrue unless KeyboardUtils.isEscape event
+ # We're now exiting insert mode.
+ if @isEditable(event.srcElement) or @isEmbed event.srcElement
+ # Remove the 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() 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()
+ @deactivate()
+ @suppressEvent
+ keypress: => if @isInsertMode then @stopBubblingAndTrue else @continueBubbling
+ keyup: => if @isInsertMode then @stopBubblingAndTrue else @continueBubbling
@handlers.push handlerStack.push
focus: (event) =>
handlerStack.alwaysPropagate =>
if not @isInsertMode and @isFocusable event.target
- @activate()
+ @activate event.target
blur: (event) =>
handlerStack.alwaysPropagate =>
- if @isInsertMode and @isFocusable event.target
+ if @isInsertMode and event.target == @insertModeLock
@deactivate()
# We may already have been dropped into insert mode. So check.