diff options
| author | mrmr1993 | 2015-06-10 17:12:09 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-06-10 20:59:46 +0100 |
| commit | 6993359b4636ed53e558218beecc8ec9deb4ed70 (patch) | |
| tree | 31d46968796ed6e4dba6cd07d0970301653162c0 /content_scripts/mode_find.coffee | |
| parent | 5bace210e738c56a8e7bee946f21041158fea7b1 (diff) | |
| download | vimium-6993359b4636ed53e558218beecc8ec9deb4ed70.tar.bz2 | |
Integrate executeFind into FindMode as FindMode.execute
Diffstat (limited to 'content_scripts/mode_find.coffee')
| -rw-r--r-- | content_scripts/mode_find.coffee | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index e6884a83..79d2be7e 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -89,7 +89,7 @@ class FindMode extends Mode # match as the user adds matching characters, or removes previously-matched characters. See #1434. @restoreSelection() query = if FindMode.query.isRegex then FindMode.getNextQueryFromRegexMatches(0) else FindMode.query.parsedQuery - FindMode.query.hasResults = executeFind query + FindMode.query.hasResults = FindMode.execute query # should be called whenever rawQuery is modified. @updateQuery: -> @@ -161,6 +161,38 @@ class FindMode extends Mode @saveQuery: -> FindModeHistory.saveQuery @query.rawQuery + # :options is an optional dict. valid parameters are 'caseSensitive' and 'backwards'. + @execute: (query, options) -> + result = null + options = extend { + backwards: false + caseSensitive: !@query.ignoreCase + colorSelection: true + }, options + query ?= FindMode.getQuery options.backwards + + if options.colorSelection + document.body.classList.add("vimiumFindMode") + # ignore the selectionchange event generated by find() + document.removeEventListener("selectionchange", @restoreDefaultSelectionHighlight, true) + + result = window.find(query, options.caseSensitive, options.backwards, true, false, true, false) + + 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 + # don't want to leave it behind (see #1412). + if document.activeElement and DomUtils.isEditable document.activeElement + document.activeElement.blur() unless DomUtils.isSelected document.activeElement + + result + + @restoreDefaultSelectionHighlight: -> document.body.classList.remove("vimiumFindMode") + getCurrentRange = -> selection = getSelection() if selection.type == "None" |
