diff options
| -rw-r--r-- | vimium.css | 6 | ||||
| -rw-r--r-- | vimiumFrontend.js | 28 |
2 files changed, 32 insertions, 2 deletions
@@ -270,4 +270,8 @@ div.vimium-completions div strong{ div.vimium-completions div.vimium-noResults{ color:#555; -}; +} + +body.vimiumFindMode ::selection { + background: #ff9632; +} diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 335f33f8..65ac240c 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -689,6 +689,15 @@ function handleKeyCharForFindMode(keyChar) { function handleEscapeForFindMode() { exitFindMode(); + document.body.classList.remove("vimiumFindMode"); + // removing the class does not re-color existing selections. we recreate the current selection so it reverts + // back to the default color. + var selection = window.getSelection(); + if (!selection.isCollapsed) { + var range = window.getSelection().getRangeAt(0); + window.getSelection().removeAllRanges(); + window.getSelection().addRange(range); + } focusFoundLink() || selectFoundInputElement(); } @@ -711,6 +720,7 @@ function handleDeleteForFindMode() { function handleEnterForFindMode() { exitFindMode(); focusFoundLink(); + document.body.classList.add("vimiumFindMode"); settings.set("findModeRawQuery", findModeQuery.rawQuery); } @@ -742,12 +752,22 @@ function performFindInPlace() { // :options is an optional dict. valid parameters are 'caseSensitive' and 'backwards'. function executeFind(query, options) { + options = options || {}; + // rather hacky, but this is our way of signalling to the insertMode listener not to react to the focus // changes that find() induces. var oldFindMode = findMode; findMode = true; - options = options || {}; + + document.body.classList.add("vimiumFindMode"); + + // ignore the selectionchange event generated by find() + document.removeEventListener("selectionchange",restoreDefaultSelectionHighlight, true); var rv = window.find(query, options.caseSensitive, options.backwards, true, false, true, false); + setTimeout(function() { + document.addEventListener("selectionchange", restoreDefaultSelectionHighlight, true); + }, 0); + findMode = oldFindMode; // we need to save the anchor node here because <esc> seems to nullify it, regardless of whether we do // preventDefault() @@ -755,6 +775,10 @@ function executeFind(query, options) { return rv; } +function restoreDefaultSelectionHighlight() { + document.body.classList.remove("vimiumFindMode"); +} + function focusFoundLink() { if (findModeQueryHasResults) { var link = getLinkFromSelection(); @@ -994,7 +1018,9 @@ function hideHelpDialog(clickEvent) { clickEvent.preventDefault(); } +// do our best to return the document to its 'default' state. function handleEscapeForNormalMode() { + window.getSelection().collapse(); if (document.activeElement !== document.body) document.activeElement.blur(); else if (window.top !== window.self) |
