From 9e14b51f7761fa35acdbf7e5abbb7bc59928a6e2 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Thu, 12 Jan 2012 13:43:26 +0800 Subject: Exit insert mode upon tab switch. Closes #314. --- vimiumFrontend.js | 9 +++++++-- 1 file 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); } -- cgit v1.2.3