diff options
| author | mrmr1993 | 2015-06-10 16:47:47 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-06-10 20:59:17 +0100 |
| commit | cef0526a2c2ef3a99a88b1c52d0c027e7e5cd0b9 (patch) | |
| tree | 7bde694017793bc2ef924c6b940aef4053bef052 | |
| parent | f7cd2560ffa40d046065d351bc73481c51b9388e (diff) | |
| download | vimium-cef0526a2c2ef3a99a88b1c52d0c027e7e5cd0b9.tar.bz2 | |
Make find from visual mode behave the same as a normal find
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 27 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 21 |
2 files changed, 27 insertions, 21 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 1be5def2..a62b2738 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -351,20 +351,19 @@ class Movement extends CountPrefix # element), or if this instance has been created to execute only a single movement. unless @options.parentMode or options.oneMovementOnly do => - executeFind = (count, findBackwards) => - if query = FindMode.getQuery findBackwards - initialRange = @selection.getRangeAt(0).cloneRange() - for [0...count] - unless window.find query, Utils.hasUpperCase(query), findBackwards, true, false, true, false - @setSelectionRange initialRange - HUD.showForDuration("No matches for '#{findModeQuery.rawQuery}'", 1000) - return - # The find was successfull. If we're in caret mode, then we should now have a selection, so we can - # drop back into visual mode. - @changeMode VisualMode if @name == "caret" and 0 < @selection.toString().length - - @movements.n = (count) -> executeFind count, false - @movements.N = (count) -> executeFind count, true + doFind = (count, backwards) => + initialRange = @selection.getRangeAt(0).cloneRange() + for [0...count] by 1 + unless executeFind null, {colorSelection: false, backwards} + @setSelectionRange initialRange + HUD.showForDuration("No matches for '#{findModeQuery.rawQuery}'", 1000) + return + # The find was successfull. If we're in caret mode, then we should now have a selection, so we can + # drop back into visual mode. + @changeMode VisualMode if @name == "caret" and 0 < @selection.toString().length + + @movements.n = (count) -> doFind count, false + @movements.N = (count) -> doFind count, true @movements["/"] = -> @findMode = new FindMode returnToViewport: true @findMode.onExit => @changeMode VisualMode diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 29267c68..6ea5080d 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -641,17 +641,24 @@ window.handleEnterForFindMode = -> # :options is an optional dict. valid parameters are 'caseSensitive' and 'backwards'. window.executeFind = (query, options) -> result = null - options = extend {backwards: false, caseSensitive: !findModeQuery.ignoreCase}, options + options = extend { + backwards: false + caseSensitive: !findModeQuery.ignoreCase + colorSelection: true + }, options query ?= FindMode.getQuery options.backwards - document.body.classList.add("vimiumFindMode") + if options.colorSelection + document.body.classList.add("vimiumFindMode") + # ignore the selectionchange event generated by find() + document.removeEventListener("selectionchange",restoreDefaultSelectionHighlight, true) - # ignore the selectionchange event generated by find() - document.removeEventListener("selectionchange",restoreDefaultSelectionHighlight, true) result = window.find(query, options.caseSensitive, options.backwards, true, false, true, false) - setTimeout( - -> document.addEventListener("selectionchange", restoreDefaultSelectionHighlight, true) - 0) + + if options.colorSelection + setTimeout( + -> document.addEventListener("selectionchange", restoreDefaultSelectionHighlight, true) + , 0) # We are either in normal mode ("n"), or find mode ("/"). We are not in insert mode. Nevertheless, if a # previous find landed in an editable element, then that element may still be activated. In this case, we |
