aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2017-11-12 16:10:59 +0000
committerGitHub2017-11-12 16:10:59 +0000
commitabacc25e39d1f4bbdc8cff61bb45079e585b75c0 (patch)
tree7b1c833939d2c7bca9fd3396a733db9384e92ff4
parent959379d46c18671551d819eb7eb2199da3ac43e2 (diff)
parent771f05845a7ce97bdff95cfb7b58cd2af8ddcae6 (diff)
downloadvimium-abacc25e39d1f4bbdc8cff61bb45079e585b75c0.tar.bz2
Merge pull request #2794 from mrmr1993/gi-tabIndex
Make focusInput respect tabIndex
-rw-r--r--content_scripts/mode_normal.coffee19
-rw-r--r--pages/options.html2
2 files changed, 18 insertions, 3 deletions
diff --git a/content_scripts/mode_normal.coffee b/content_scripts/mode_normal.coffee
index ee05f4b0..027ad22f 100644
--- a/content_scripts/mode_normal.coffee
+++ b/content_scripts/mode_normal.coffee
@@ -144,7 +144,23 @@ NormalModeCommands =
for i in [0...resultSet.snapshotLength] by 1
element = resultSet.snapshotItem i
continue unless DomUtils.getVisibleClientRect element, true
- { element, rect: Rect.copy element.getBoundingClientRect() }
+ { element, index: i, rect: Rect.copy element.getBoundingClientRect() }
+
+ visibleInputs.sort ({element: element1, index: i1}, {element: element2, index: i2}) ->
+ # Put elements with a lower positive tabIndex first, keeping elements in DOM order.
+ if element1.tabIndex > 0
+ if element2.tabIndex > 0
+ tabDifference = element1.tabIndex - element2.tabIndex
+ if tabDifference != 0
+ tabDifference
+ else
+ i1 - i2
+ else
+ -1
+ else if element2.tabIndex > 0
+ 1
+ else
+ i1 - i2
if visibleInputs.length == 0
HUD.showForDuration("There are no inputs to focus.", 1000)
@@ -153,7 +169,6 @@ NormalModeCommands =
# This is a hack to improve usability on the Vimium options page. We prime the recently-focused input
# to be the key-mappings input. Arguably, this is the input that the user is most likely to use.
recentlyFocusedElement = lastFocusedInput()
- recentlyFocusedElement ?= document.getElementById "keyMappings" if window.isVimiumOptionsPage
selectedInputIndex =
if count == 1
diff --git a/pages/options.html b/pages/options.html
index ec940cb2..650a129c 100644
--- a/pages/options.html
+++ b/pages/options.html
@@ -67,7 +67,7 @@ unmapAll
<a href="#" id="showCommands">Show available commands</a>.
</div>
</div>
- <textarea id="keyMappings" type="text"></textarea>
+ <textarea id="keyMappings" type="text" tabIndex="1"></textarea>
</td>
</tr>
<tr>