From 05351d4650ace35574bf4f9c55cced65950252f5 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 25 Jan 2015 09:37:29 +0000 Subject: Visual/edit modes: find (experimental). The UX around find in visual mode can be a bit weird. It may be better to remove it. --- content_scripts/mode_visual_edit.coffee | 25 ++++++++++++++++++++++++- content_scripts/vimium_frontend.coffee | 12 +++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'content_scripts') 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 }) -- cgit v1.2.3