aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-20 10:24:45 +0000
committerStephen Blott2015-01-20 10:24:45 +0000
commit7939b69ffc2880ff4590d1c8dcfd5eb7492200fd (patch)
tree46ebe99b79975c684dd03d8ebbb047dfacc8ce58
parent7f65764ab4961c8e8f1a2ec25a02a52dd8255cf6 (diff)
downloadvimium-7939b69ffc2880ff4590d1c8dcfd5eb7492200fd.tar.bz2
Rework focus input so it can be better included in tests.
focusInput was getting its focus events from the handler stack. When the handler stack was reset during tests, we lost focusInput's handler. So we couldn't test the feature whereby focusInput has a memory (#1438). Instead, here focusInput adds its listener directly to the window, and we add the approriate test.
-rw-r--r--content_scripts/vimium_frontend.coffee8
-rw-r--r--tests/dom_tests/dom_tests.coffee5
2 files changed, 8 insertions, 5 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 729a21bd..5d56ad5b 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -337,11 +337,9 @@ extend window,
focusInput: do ->
# Track the most recently focused input element.
recentlyFocusedElement = null
- handlerStack.push
- _name: "focus-input-tracker"
- focus: (event) ->
- recentlyFocusedElement = event.target if DomUtils.isEditable event.target
- true
+ window.addEventListener "focus",
+ (event) -> recentlyFocusedElement = event.target if DomUtils.isEditable event.target
+ , true
(count) ->
# Focus the first input element on the page, and create overlays to highlight all the input elements, with
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee
index b0ee1a66..11fbe11f 100644
--- a/tests/dom_tests/dom_tests.coffee
+++ b/tests/dom_tests/dom_tests.coffee
@@ -218,6 +218,11 @@ context "Input focus",
focusInput 100
assert.isTrue InsertMode.permanentInstance.isActive()
+ should "activate the most recently-selected input if the count is 1", ->
+ focusInput 3
+ focusInput 1
+ assert.equal "third", document.activeElement.id
+
should "not trigger insert if there are no inputs", ->
document.getElementById("test-div").innerHTML = ""
focusInput 1