diff options
| author | jez | 2011-05-19 15:02:44 +0000 |
|---|---|---|
| committer | jez | 2011-05-19 15:46:19 +0000 |
| commit | eeba8a63c120b39c48fa7d37e8d1a3c9afcb0270 (patch) | |
| tree | 1260f61f92223a45e955afe04c12bac80b4b37e7 /vimiumFrontend.js | |
| parent | b5f380fb5e71bb5f3ec5f669f030483c80a371ef (diff) | |
| download | vimium-eeba8a63c120b39c48fa7d37e8d1a3c9afcb0270.tar.bz2 | |
Focus links after having found them. Closes #132.
Specifically, we focus a link when:
1. The user exits find mode with the link selected.
2. The user presses 'n' or 'N'.
Also rename 'findModeQueryHasResults' to 'hasResults' to avoid confusion with
the global variable of the same name.
Diffstat (limited to 'vimiumFrontend.js')
| -rw-r--r-- | vimiumFrontend.js | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js index b79abfde..ee19d90f 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -613,31 +613,54 @@ function performFindInPlace() { // backwards. window.scrollTo(cachedScrollX, cachedScrollY); - performFind(); + executeFind(); +} + +function executeFind(backwards) { + findModeQueryHasResults = window.find(findModeQuery, false, backwards, true, false, true, false); +} + +function focusFoundLink() { + if (findModeQueryHasResults) { + var link = getLinkFromSelection(); + if (link) link.focus(); + } +} + +function findAndFocus(backwards) { + executeFind(backwards); + focusFoundLink(); } function performFind() { - findModeQueryHasResults = window.find(findModeQuery, false, false, true, false, true, false); + findAndFocus(); } function performBackwardsFind() { - findModeQueryHasResults = window.find(findModeQuery, false, true, true, false, true, false); + findAndFocus(true); +} + +function getLinkFromSelection() { + var node = window.getSelection().anchorNode; + while (node.nodeName.toLowerCase() !== 'body') { + if (node.nodeName.toLowerCase() === 'a') return node; + node = node.parentNode; + } + return null; } function findAndFollowLink(linkStrings) { for (i = 0; i < linkStrings.length; i++) { - var findModeQueryHasResults = window.find(linkStrings[i], false, true, true, false, true, false); - if (findModeQueryHasResults) { - var node = window.getSelection().anchorNode; - while (node.nodeName.toLowerCase() != 'body') { - if (node.nodeName.toLowerCase() == 'a') { - window.location = node.href; - return true; - } - node = node.parentNode; + var hasResults = window.find(linkStrings[i], false, true, true, false, true, false); + if (hasResults) { + var link = getLinkFromSelection(); + if (link) { + window.location = link.href; + return true; } } } + return false; } function findAndFollowRel(value) { @@ -698,6 +721,7 @@ function enterFindMode() { function exitFindMode() { findMode = false; + focusFoundLink(); HUD.hide(); } |
