Permalink
Browse files

Color find matches orange.

The brighter color makes them more visible. The orange is chosen to
match Chrome's default color.
  • Loading branch information...
1 parent baace1c commit 1e04eb8c3b57701206ddd65bf3b3292f0678e3e1 @int3 int3 committed Jan 26, 2012
Showing with 32 additions and 2 deletions.
  1. +5 −1 vimium.css
  2. +27 −1 vimiumFrontend.js
View
@@ -270,4 +270,8 @@ div.vimium-completions div strong{
div.vimium-completions div.vimium-noResults{
color:#555;
-};
+}
+
+body.vimiumFindMode ::selection {
+ background: #ff9632;
+}
View
@@ -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,19 +752,33 @@ 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()
findModeAnchorNode = document.getSelection().anchorNode;
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)

0 comments on commit 1e04eb8

Please sign in to comment.