diff options
| author | Stephen Blott | 2015-01-25 09:37:29 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-25 10:36:52 +0000 |
| commit | 05351d4650ace35574bf4f9c55cced65950252f5 (patch) | |
| tree | 4054f01f07b2c581723a8528e15bfa947c080b26 | |
| parent | 9c4603680284a4e00f11b097aebc65c6f6c0af07 (diff) | |
| download | vimium-05351d4650ace35574bf4f9c55cced65950252f5.tar.bz2 | |
Visual/edit modes: find (experimental).
The UX around find in visual mode can be a bit weird. It may be better
to remove it.
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 25 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 12 |
2 files changed, 31 insertions, 6 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 12d8bf4a..261166f9 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -2,7 +2,7 @@ # To do: # - better implementation of `o` # - caret mode -# - find operations +# - find operations (needs better implementation?) # This prevents printable characters from being passed through to underlying page. It should, however, allow # through chrome keyboard shortcuts. It's a backstop for all of the modes following. @@ -286,6 +286,29 @@ class VisualMode extends Movement "d": -> @yank deleteFromDocument: true "c": -> @yank(); enterInsertMode() + # Map "n" and "N" for poor-man's find. + unless @options.underEditMode + do => + findBackwards = false + query = getFindModeQuery() + return unless query + + executeFind = => @protectClipboard => + initialRange = @selection.getRangeAt(0).cloneRange() + caseSensitive = /[A-Z]/.test query + if query + window.find query, caseSensitive, findBackwards, true, false, true, false + newRange = @selection.getRangeAt(0).cloneRange() + range = document.createRange() + range.setStart initialRange.startContainer, initialRange.startOffset + range.setEnd newRange.endContainer, newRange.endOffset + @selection.removeAllRanges() + @selection.addRange range + + extend @movements, + "n": -> executeFind() + "N": -> findBackwards = not findBackwards; executeFind() + @clipboardContents = "" @paste (text) => @clipboardContents = text diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 5fe40e5a..65fd0b97 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -864,6 +864,12 @@ getNextQueryFromRegexMatches = (stepSize) -> findModeQuery.regexMatches[findModeQuery.activeRegexIndex] +window.getFindModeQuery = -> + if findModeQuery.isRegex + getNextQueryFromRegexMatches(if backwards then -1 else 1) + else + findModeQuery.parsedQuery + findAndFocus = (backwards) -> # check if the query has been changed by a script in another frame mostRecentQuery = settings.get("findModeRawQuery") || "" @@ -871,11 +877,7 @@ findAndFocus = (backwards) -> findModeQuery.rawQuery = mostRecentQuery updateFindModeQuery() - query = - if findModeQuery.isRegex - getNextQueryFromRegexMatches(if backwards then -1 else 1) - else - findModeQuery.parsedQuery + query = getFindModeQuery() findModeQueryHasResults = executeFind(query, { backwards: backwards, caseSensitive: !findModeQuery.ignoreCase }) |
