aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-01-18 21:43:28 +0000
committerStephen Blott2015-01-18 22:03:18 +0000
commit7450e1cfc57231457c894d372774c391bf13ac68 (patch)
treebcf552eb8917fa249c8350a21bb895a06eabf57d
parent9d7185b78b366abafe52faeb18ec039b242e02b9 (diff)
downloadvimium-7450e1cfc57231457c894d372774c391bf13ac68.tar.bz2
Give focusInput a memory (refactor).
This makes the diff look big, but that's mainly due to a change in the indentation.
-rw-r--r--content_scripts/vimium_frontend.coffee19
1 files changed, 11 insertions, 8 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 6cc686d2..725d8a53 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -332,21 +332,23 @@ extend window,
new VisualMode()
focusInput: do ->
- # Track the most-recently focused input element.
- focusedElement = null
+ # Track the most recently focused input element.
+ recentlyFocusedElement = null
handlerStack.push
+ _name: "focus-input-tracker"
focus: (event) ->
- focusedElement = event.target if DomUtils.isEditable event.target
+ 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
# the currently-focused element highlighted specially. Tabbing will shift focus to the next input element.
# Pressing any other key will remove the overlays and the special tab behavior.
- resultSet = DomUtils.evaluateXPath(textInputXPath, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE)
+ resultSet = DomUtils.evaluateXPath textInputXPath, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE
visibleInputs =
for i in [0...resultSet.snapshotLength] by 1
- element = resultSet.snapshotItem(i)
- rect = DomUtils.getVisibleClientRect(element)
+ element = resultSet.snapshotItem i
+ rect = DomUtils.getVisibleClientRect element
continue if rect == null
{ element: element, rect: rect }
@@ -354,13 +356,14 @@ extend window,
selectedInputIndex =
if count == 1
+ # As the starting index, we pick that of the most recently focused input element (or 0).
elements = visibleInputs.map (visibleInput) -> visibleInput.element
- Math.max 0, elements.indexOf focusedElement
+ Math.max 0, elements.indexOf recentlyFocusedElement
else
Math.min(count, visibleInputs.length) - 1
hints = for tuple in visibleInputs
- hint = document.createElement("div")
+ hint = document.createElement "div"
hint.className = "vimiumReset internalVimiumInputHint vimiumInputHint"
# minus 1 for the border