Skip to content

Commit

Permalink
Exit insert mode upon tab switch. Closes philc#314.
Browse files Browse the repository at this point in the history
  • Loading branch information
int3 committed Jan 12, 2012
1 parent b577864 commit 9e14b51
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vimiumFrontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 9e14b51

Please sign in to comment.