aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/mode_visual_edit.coffee25
-rw-r--r--content_scripts/vimium_frontend.coffee12
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 })