diff options
| author | mrmr1993 | 2017-10-24 19:22:20 +0100 | 
|---|---|---|
| committer | mrmr1993 | 2017-10-27 20:34:28 +0100 | 
| commit | ca9aa228f1999540063063e6cb86a7baeba9da93 (patch) | |
| tree | adf1279618e7da8df7d61664483ebae19e215bd0 | |
| parent | 0b24e966c6a64864204c7f489063b29e05b2ca34 (diff) | |
| download | vimium-ca9aa228f1999540063063e6cb86a7baeba9da93.tar.bz2 | |
Move FindMode exit functions into FindMode
| -rw-r--r-- | content_scripts/hud.coffee | 6 | ||||
| -rw-r--r-- | content_scripts/mode_find.coffee | 20 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 23 | 
3 files changed, 24 insertions, 25 deletions
| diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 6185d786..7c983cfa 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -71,13 +71,13 @@ HUD =      focusNode?.focus?()      if exitEventIsEnter -      handleEnterForFindMode() +      FindMode.handleEnter()        if FindMode.query.hasResults          postExit = -> new PostFindMode      else if exitEventIsEscape -      # We don't want FindMode to handle the click events that handleEscapeForFindMode can generate, so we +      # We don't want FindMode to handle the click events that FindMode.handleEscape can generate, so we        # wait until the mode is closed before running it. -      postExit = handleEscapeForFindMode +      postExit = FindMode.handleEscape      @findMode.exit()      postExit?() diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 5238ab34..8dc3bdcc 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -79,7 +79,7 @@ class FindMode extends Mode    exit: (event) ->      super() -    handleEscapeForFindMode() if event +    FindMode.handleEscape() if event    restoreSelection: ->      range = @initialRange @@ -201,6 +201,24 @@ class FindMode extends Mode    @restoreDefaultSelectionHighlight: forTrusted -> document.body.classList.remove("vimiumFindMode") +  # The user has found what they're looking for and is finished searching. We enter insert mode, if possible. +  @handleEscape: -> +    document.body.classList.remove("vimiumFindMode") +    # Removing the class does not re-color existing selections. we recreate the current selection so it reverts +    # back to the default color. +    selection = window.getSelection() +    unless selection.isCollapsed +      range = window.getSelection().getRangeAt(0) +      window.getSelection().removeAllRanges() +      window.getSelection().addRange(range) +    focusFoundLink() || selectFoundInputElement() + +  # Save the query so the user can do further searches with it. +  @handleEnter: -> +    focusFoundLink() +    document.body.classList.add("vimiumFindMode") +    FindMode.saveQuery() +    checkReturnToViewPort: ->      window.scrollTo @scrollX, @scrollY if @options.returnToViewport diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 530e96c3..a01551a8 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -423,25 +423,6 @@ checkIfEnabledForUrl = do ->  checkEnabledAfterURLChange = forTrusted ->    checkIfEnabledForUrl() if windowIsFocused() -handleEscapeForFindMode = -> -  document.body.classList.remove("vimiumFindMode") -  # removing the class does not re-color existing selections. we recreate the current selection so it reverts -  # back to the default color. -  selection = window.getSelection() -  unless selection.isCollapsed -    range = window.getSelection().getRangeAt(0) -    window.getSelection().removeAllRanges() -    window.getSelection().addRange(range) -  focusFoundLink() || selectFoundInputElement() - -# <esc> sends us into insert mode if possible, but <cr> does not. -# <esc> corresponds approximately to 'nevermind, I have found it already' while <cr> means 'I want to save -# this query and do more searches with it' -handleEnterForFindMode = -> -  focusFoundLink() -  document.body.classList.add("vimiumFindMode") -  FindMode.saveQuery() -  focusFoundLink = ->    if (FindMode.query.hasResults)      link = getLinkFromSelection() @@ -604,8 +585,8 @@ root.Frame = Frame  root.windowIsFocused = windowIsFocused  root.bgLog = bgLog  # These are exported for find mode and link-hints mode. -extend root, {handleEscapeForFindMode, handleEnterForFindMode, performFind, performBackwardsFind, -  enterFindMode, focusThisFrame} +extend root, {focusFoundLink, selectFoundInputElement, performFind, performBackwardsFind, enterFindMode, +  focusThisFrame}  # These are exported only for the tests.  extend root, {installModes}  extend window, root unless exports? | 
