diff options
| author | Stephen Blott | 2015-01-18 13:07:39 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-18 13:07:39 +0000 |
| commit | a938c55e0a08d82abbd200a8e7609ceaa8ee539a (patch) | |
| tree | d2943c799c9fd3260b020b4f76c82bf548ade386 | |
| parent | 0f2343dbc73b4bbca856b777b8a3c11b0cffd2cd (diff) | |
| download | vimium-a938c55e0a08d82abbd200a8e7609ceaa8ee539a.tar.bz2 | |
Give focusInput a memory.
- Track the most recently-focused input.
- When focusInput is launched (with a count of 1) start with the most
recently focused input.
This does two things:
- If the user is editing an element then comes back, they end up back
where they started.
- It gives focusInput a memory.
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 35d92f3c..c49c27e2 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -331,6 +331,17 @@ extend window, enterVisualMode: => new VisualMode() +# Track the most-recently focused input element. This is used by focusInput to decide which input to initially +# highlight. +getFocusedElementIndexByRecency = do -> + focusedElement = null + installListener window, "focus", (event) -> + focusedElement = event.target if DomUtils.isEditable event.target + + (elements) -> + Math.max 0, elements.indexOf focusedElement + +extend window, focusInput: (count) -> # Focus the first input element on the page, and create overlays to highlight all the input elements, with # the currently-focused element highlighted specially. Tabbing will shift focus to the next input element. @@ -345,7 +356,11 @@ extend window, return if visibleInputs.length == 0 - selectedInputIndex = Math.min(count - 1, visibleInputs.length - 1) + selectedInputIndex = + if count == 1 + getFocusedElementIndexByRecency visibleInputs.map (visibleInput) -> visibleInput.element + else + Math.min(count, visibleInputs.length) - 1 hints = for tuple in visibleInputs hint = document.createElement("div") |
