diff options
| author | Phil Crosby | 2009-12-31 02:29:58 -0500 |
|---|---|---|
| committer | Phil Crosby | 2009-12-31 02:29:58 -0500 |
| commit | 198ef63cbfdcab7f8fef72bf6144964ed5b76cf6 (patch) | |
| tree | fedf5897739c6f9332622f4300d7b73d4d897007 | |
| parent | cccd76bc46633a81dcdbe80b08b3f70f7737c2b6 (diff) | |
| download | vimium-198ef63cbfdcab7f8fef72bf6144964ed5b76cf6.tar.bz2 | |
Fix a race condition where domready would be fired prior to 'initializeWhenEnabled', breaking our initial input-is-focused detection
| -rw-r--r-- | vimiumFrontend.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 58113e1a..a1ad7c9c 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -115,25 +115,33 @@ function initializeWhenEnabled() { document.addEventListener("keydown", onKeydown); document.addEventListener("focus", onFocusCapturePhase, true); document.addEventListener("blur", onBlurCapturePhase, true); + enterInsertModeIfElementIsFocused(); } /* * Initialization tasks that must wait for the document to be ready. */ function initializeOnDomReady() { - if (isEnabledForUrl) { - // Enter insert mode automatically if there's already a text box focused. - var focusNode = window.getSelection().focusNode; - var focusOffset = window.getSelection().focusOffset; - if (focusNode && focusOffset && focusNode.children.length > focusOffset && - isInputOrText(focusNode.children[focusOffset])) - enterInsertMode(); - } + if (isEnabledForUrl) + enterInsertModeIfElementIsFocused(); // Tell the background page we're in the dom ready state. chrome.extension.connect({ name: "domReady" }); }; /* + * Checks the currently focused element of the document and will enter insert mode if that element is focusable. + */ +function enterInsertModeIfElementIsFocused() { + // Enter insert mode automatically if there's already a text box focused. + // TODO(philc): Consider using document.activeElement here instead. + var focusNode = window.getSelection().focusNode; + var focusOffset = window.getSelection().focusOffset; + if (focusNode && focusOffset && focusNode.children.length > focusOffset && + isInputOrText(focusNode.children[focusOffset])) + enterInsertMode(); +} + +/* * Asks the background page to persist the zoom level for the given domain to localStorage. */ function saveZoomLevel(domain, zoomLevel) { |
