aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-04-02 13:39:36 +0100
committerStephen Blott2016-04-02 13:39:38 +0100
commitdeca2ecb726174303dd024209585e522b79e33b8 (patch)
treeb2347dd9cd266cdd1e55f16797ddecc5db39581c
parenteb1b9ee9b4db56068cdc6b7864a6ff1a0fbf1ee4 (diff)
downloadvimium-deca2ecb726174303dd024209585e522b79e33b8.tar.bz2
Make stableSortCount per instance.
I've not observed this, but it could possily happen... If the stableSortCount gets out of sync in different frames, then different frames might make different decisions about the ordering of the hints. Ti avoid this potentially happening, we initialise the stableSortCount every time link-hints mode is activated.
-rw-r--r--content_scripts/link_hints.coffee31
1 files changed, 15 insertions, 16 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 01ed6de5..53b5e062 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -131,6 +131,8 @@ class LinkHintsMode
HUD.showForDuration "No links to select.", 2000
return
+ # This count is used to rank equal-scoring hints when sorting, thereby making JavaScript's sort stable.
+ @stableSortCount = 0
@hintMarkers = (@createMarkerFor desc for desc in hintDescriptors)
@markerMatcher = new (if Settings.get "filterLinkHints" then FilterHints else AlphabetHints)
@markerMatcher.fillInMarkers @hintMarkers
@@ -168,22 +170,19 @@ class LinkHintsMode
#
# Creates a link marker for the given link.
#
- createMarkerFor: do ->
- # This count is used to rank equal-scoring hints when sorting, thereby making JavaScript's sort stable.
- stableSortCount = 0
- (desc) ->
- marker = DomUtils.createElement "div"
- marker.className = "vimiumReset internalVimiumHintMarker vimiumHintMarker"
- marker.stableSortCount = ++stableSortCount
- # Extract other relevant fields from the hint descriptor.
- extend marker,
- {hintDescriptor: desc, linkText: desc.linkText, showLinkText: desc.showLinkText, rect: desc.rect}
-
- clientRect = desc.rect
- marker.style.left = clientRect.left + window.scrollX + "px"
- marker.style.top = clientRect.top + window.scrollY + "px"
-
- marker
+ createMarkerFor: (desc) ->
+ marker = DomUtils.createElement "div"
+ marker.className = "vimiumReset internalVimiumHintMarker vimiumHintMarker"
+ marker.stableSortCount = ++@stableSortCount
+ # Extract other relevant fields from the hint descriptor.
+ extend marker,
+ {hintDescriptor: desc, linkText: desc.linkText, showLinkText: desc.showLinkText, rect: desc.rect}
+
+ clientRect = desc.rect
+ marker.style.left = clientRect.left + window.scrollX + "px"
+ marker.style.top = clientRect.top + window.scrollY + "px"
+
+ marker
# Handles <Shift> and <Ctrl>.
onKeyDownInMode: (event) ->