diff options
| author | ilya | 2009-11-13 23:19:53 -0800 |
|---|---|---|
| committer | ilya | 2009-11-13 23:35:12 -0800 |
| commit | 61b30ebbc3e1f9c7507a5f85a466f1388df5d56a (patch) | |
| tree | e0d2552f9d1ba3531ea1fdc84924fd6f45f1bbee /vimiumFrontend.js | |
| parent | 1c118bd084e4c228472690a1edb171889678925f (diff) | |
| download | vimium-61b30ebbc3e1f9c7507a5f85a466f1388df5d56a.tar.bz2 | |
Enter insert mode if the content script loads with a text input already focused before we can add event handlers (e.g. google). Also blur the text box if the user exits insert mode. Closes #4.
Diffstat (limited to 'vimiumFrontend.js')
| -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(); |
