aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilya2009-12-07 23:30:40 -0800
committerilya2009-12-07 23:30:40 -0800
commita735d5c675f746610750b29e67b61bd900ddd7c6 (patch)
tree0ab29a426f9906f1fcf89a4b653d21936e69ebe3
parent30a11474705be9cf7399bc997d27b2cb089b4cb3 (diff)
downloadvimium-a735d5c675f746610750b29e67b61bd900ddd7c6.tar.bz2
Cooked up some in-place finding. The search results won't jump around the page until you hit enter and use 'n' or 'N'. While you type the first matching result will stick. Closes #24.
-rw-r--r--vimiumFrontend.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index c50380b0..d27d648d 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -237,7 +237,7 @@ function exitInsertMode() {
function handleKeyCharForFindMode(keyChar) {
findModeQuery = findModeQuery + keyChar;
showFindModeHUDForQuery();
- performFind();
+ performFindInPlace();
}
function handleDeleteForFindMode() {
@@ -249,12 +249,26 @@ function handleDeleteForFindMode() {
showFindModeHUDForQuery();
}
- performFind();
+ performFindInPlace();
}
function handleEnterForFindMode() {
exitFindMode();
+ performFindInPlace();
+}
+
+function performFindInPlace() {
+ var cachedScrollX = window.scrollX;
+ var cachedScrollY = window.scrollY;
+
+ // Search backwards first to "free up" the current word as eligible for the real forward search. This allows
+ // us to search in place without jumping around between matches as the query grows.
+ window.find(findModeQuery, false, true, true, false, true, false);
performFind();
+
+ // We need to restore the scroll position because we might've lost the right position by searching
+ // backwards.
+ window.scrollTo(cachedScrollX, cachedScrollY);
}
function performFind() {
@@ -399,3 +413,4 @@ if (!isIframe) {
initializePreDomReady();
window.addEventListener("DOMContentLoaded", initializeOnDomReady);
}
+