diff options
| -rw-r--r-- | content_scripts/link_hints.coffee | 5 | ||||
| -rw-r--r-- | content_scripts/mode.coffee | 4 | ||||
| -rw-r--r-- | content_scripts/mode_insert.coffee | 31 |
3 files changed, 22 insertions, 18 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index ad2afaa2..0668e3ae 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -72,15 +72,14 @@ LinkHints = name: "hint/#{mode.name}" badge: "#{mode.key}?" exitOnEscape: true - exitOnClick: true keydown: (event) -> LinkHints.onKeyDownInMode hintMarkers, event - # trap all key events + # trap all other keyboard events keypress: => @stopBubblingAndFalse keyup: => @stopBubblingAndFalse exit: (delay, callback) => - super() LinkHints.deactivateMode delay, callback + super() setOpenLinkMode: (@mode) -> if @mode is OPEN_IN_NEW_BG_TAB or @mode is OPEN_IN_NEW_FG_TAB or @mode is OPEN_WITH_QUEUE diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index d06f5eae..84b76301 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -101,7 +101,9 @@ class Mode if @options.exitOnClick @push _name: "mode-#{@id}/exitOnClick" - "click": (event) => @alwaysContinueBubbling => @exit() + "click": (event) => @alwaysContinueBubbling => + @clickEvent = event + @exit() # If @options.trackState is truthy, then the mode mainatins the current state in @enabled and @passKeys, # and calls @registerStateChange() (if defined) whenever the state changes. diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index 5720c901..dd0c8d16 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -73,12 +73,13 @@ triggerSuppressor = new Utils.Suppressor true # Note: true == @continueBubbling # unintentionally dropping into insert mode on focusable elements. class InsertModeBlocker extends Mode constructor: (options = {}) -> + defaults = + name: "insert-blocker" + # The user knows best; so, if the user clicks on something, the insert-mode blocker gets out of the way. + exitOnClick: true + onClickMode: InsertMode + super extend defaults, options triggerSuppressor.suppress() - options.name ||= "insert-blocker" - # See "click" handler below for an explanation of options.onClickMode. - options.onClickMode ||= InsertMode - super options - @onExit -> triggerSuppressor.unsuppress() @push _name: "mode-#{@id}/bail-on-click" @@ -86,15 +87,17 @@ class InsertModeBlocker extends Mode @alwaysContinueBubbling => # The user knows best; so, if the user clicks on something, the insert-mode blocker gets out of the # way. - @exit event - # However, there's a corner case. If the active element is focusable, then, had we not been - # blocking the trigger, we would already have been in insert mode. Now, a click on that element - # will not generate a new focus event, so the insert-mode trigger will not fire. We have to handle - # this case specially. @options.onClickMode specifies the mode to use (by default, insert mode). - if document.activeElement and - event.target == document.activeElement and DomUtils.isEditable document.activeElement - new @options.onClickMode - targetElement: document.activeElement + + exit: -> + super() + # If the element associated with the event is focusable, then, had we not been blocking the trigger, we + # would already have been in insert mode. Now, a click on that element will not generate a new focus + # event, so the insert-mode trigger will not fire. We have to handle this case specially. + # @options.onClickMode specifies the mode to use (by default, insert mode). + if @clickEvent?.target? and DomUtils.isFocusable @clickEvent.target + new @options.onClickMode + targetElement: event.target + triggerSuppressor.unsuppress() root = exports ? window root.InsertMode = InsertMode |
