aboutsummaryrefslogtreecommitdiffstats
path: root/vimiumFrontend.js
diff options
context:
space:
mode:
authorJez Ng2012-01-12 13:43:26 +0800
committerJez Ng2012-01-13 01:08:13 +0800
commit9e14b51f7761fa35acdbf7e5abbb7bc59928a6e2 (patch)
treef95bf6aeaac7eb0d42fef7a1ac0f9652f5d7071e /vimiumFrontend.js
parentb57786445e493e1e1b7ca35fd3d8e51f797682cb (diff)
downloadvimium-9e14b51f7761fa35acdbf7e5abbb7bc59928a6e2.tar.bz2
Exit insert mode upon tab switch. Closes #314.
Diffstat (limited to 'vimiumFrontend.js')
-rw-r--r--vimiumFrontend.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index 594438e9..736f14b0 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -158,7 +158,7 @@ function initializeWhenEnabled() {
document.addEventListener("keypress", onKeypress, true);
document.addEventListener("keyup", onKeyup, true);
document.addEventListener("focus", onFocusCapturePhase, true);
- document.addEventListener("blur", onBlurCapturePhase, true);
+ window.addEventListener("blur", onBlurCapturePhase, true);
enterInsertModeIfElementIsFocused();
}
@@ -479,7 +479,12 @@ function onFocusCapturePhase(event) {
}
function onBlurCapturePhase(event) {
- if (isFocusable(event.target))
+ if (event.target == window)
+ // At this point, we will have exited insert mode already, but the browser remembers which element last
+ // had focus, and fires a focus event on it when the window regains focus. We blur this element to prevent
+ // implicit insert mode from reactivating when we switch back to this tab.
+ document.activeElement.blur();
+ else if (isFocusable(event.target))
exitInsertMode(event.target);
}