diff options
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 35 | 
1 files changed, 20 insertions, 15 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 75b4172f..299cdcf2 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -134,7 +134,7 @@ initializePreDomReady = ->    # Install passKeys and insert modes.  These too are permanently on the stack (although not always active).    passKeysMode = new PassKeysMode() -  insertMode = new InsertMode() +  new InsertModeTrigger()    Mode.updateBadge()    checkIfEnabledForUrl() @@ -339,12 +339,14 @@ extend window,      HUD.showForDuration("Yanked URL", 1000)    enterInsertMode: -> -    insertMode?.activate() +    new InsertMode()    enterVisualMode: =>      new VisualMode()    focusInput: (count) -> +    SingletonMode.kill PostFindMode +      # Focus the first input element on the page, and create overlays to highlight all the input elements, with      # the currently-focused element highlighted specially. Tabbing will shift focus to the next input element.      # Pressing any other key will remove the overlays and the special tab behavior. @@ -360,10 +362,14 @@ extend window,      selectedInputIndex = Math.min(count - 1, visibleInputs.length - 1) -    # See the definition of PostFindMode.exitModeAndEnterInsert for an explanation of why this is needed. -    PostFindMode.exitModeAndEnterInsert insertMode, visibleInputs[selectedInputIndex].element - -    visibleInputs[selectedInputIndex].element.focus() +    # There's feature interference between PostFindMode, InsertMode and focusInput.  PostFindMode prevents +    # InsertMode from triggering on focus events.  Therefore, an input element can already be focused, but +    # InsertMode is not active.  When that element is then (again) focused by focusInput, below, no new focus +    # event is generated, so we don't drop into InsertMode as expected. +    # Therefore we blur() the element before focussing it. +    element = visibleInputs[selectedInputIndex].element +    element.blur() if document.activeElement == element +    element.focus()      return if visibleInputs.length == 1 @@ -730,14 +736,12 @@ handleEnterForFindMode = ->    focusFoundLink()    document.body.classList.add("vimiumFindMode")    settings.set("findModeRawQuery", findModeQuery.rawQuery) -  # If we have found an input element, the pressing <esc> immediately afterwards sends us into insert mode. -  new PostFindMode insertMode, findModeAnchorNode  class FindMode extends ExitOnEscapeMode -  constructor: (badge="F") -> -    super +  constructor: -> +    super FindMode,        name: "find" -      badge: badge +      badge: "/"        keydown: (event) =>          if event.keyCode == keyCodes.backspace || event.keyCode == keyCodes.deleteKey @@ -761,9 +765,10 @@ class FindMode extends ExitOnEscapeMode      Mode.updateBadge() -  exit: (event) -> -    handleEscapeForFindMode() if event?.source == ExitOnEscapeMode +  exit: (extra) -> +    handleEscapeForFindMode() if extra?.source == ExitOnEscapeMode      super() +    new PostFindMode findModeAnchorNode  performFindInPlace = ->    cachedScrollX = window.scrollX @@ -792,7 +797,7 @@ executeFind = (query, options) ->    HUD.hide(true)    # ignore the selectionchange event generated by find()    document.removeEventListener("selectionchange",restoreDefaultSelectionHighlight, true) -  Mode.runIn InsertModeSuppressFocusTrigger, -> +  Mode.runIn InsertModeBlocker, ->      result = window.find(query, options.caseSensitive, options.backwards, true, false, true, false)    setTimeout(      -> document.addEventListener("selectionchange", restoreDefaultSelectionHighlight, true) @@ -854,7 +859,7 @@ findAndFocus = (backwards) ->    # if we have found an input element via 'n', pressing <esc> immediately afterwards sends us into insert    # mode -  new PostFindMode insertMode, findModeAnchorNode +  new PostFindMode findModeAnchorNode    focusFoundLink()  | 
