diff options
| -rw-r--r-- | vimiumFrontend.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 88aa718f..29cd1240 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -44,6 +44,11 @@ function initializeFrontend() { }); } }); + + // Enter insert mode automatically if there's already a text box focused. + var focusNode = window.getSelection().focusNode; + var focusOffset = window.getSelection().focusOffset; + if (isInputOrText(focusNode.children[focusOffset])) { enterInsertMode(); } }; /* @@ -100,7 +105,11 @@ function onKeydown(event) { } if (insertMode && event.keyCode == keyCodes.ESC) + { + // Remove focus so the user can't just get himself back into insert mode by typing in the same input box. + if (isInputOrText(event.srcElement)) { event.srcElement.blur(); } exitInsertMode(); + } else if (!insertMode && keyChar) keyPort.postMessage(keyChar); } @@ -115,6 +124,10 @@ function onBlurCapturePhase(event) { exitInsertMode(); } +function isInputOrText(target) { + return (target.tagName == "INPUT" || target.tagName == "TEXTAREA"); +} + function enterInsertMode() { insertMode = true; HUD.show("Insert mode"); @@ -164,4 +177,4 @@ HUD = { // This should be revisited, because sometimes we *do* want to listen inside of the currently focused iframe. var isIframe = (window.self != window.parent); if (!isIframe) - initializeFrontend();
\ No newline at end of file + initializeFrontend(); |
