aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content_scripts/link_hints.coffee73
-rw-r--r--content_scripts/vimium_frontend.coffee35
-rw-r--r--lib/utils.coffee1
-rw-r--r--tests/dom_tests/dom_tests.coffee4
4 files changed, 17 insertions, 96 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 3b08dcd9..0b1bb20e 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -415,8 +415,6 @@ class LinkHintsMode
# Use characters for hints, and do not filter links by their text.
class AlphabetHints
- logXOfBase: (x, base) -> Math.log(x) / Math.log(base)
-
constructor: ->
@linkHintCharacters = Settings.get "linkHintCharacters"
# We use the keyChar from keydown if the link-hint characters are all "a-z0-9". This is the default
@@ -439,39 +437,16 @@ class AlphabetHints
# may be of different lengths.
#
hintStrings: (linkCount) ->
- # Determine how many digits the link hints will require in the worst case. Usually we do not need
- # all of these digits for every link single hint, so we can show shorter hints for a few of the links.
- digitsNeeded = Math.ceil(@logXOfBase(linkCount, @linkHintCharacters.length))
- # Short hints are the number of hints we can possibly show which are (digitsNeeded - 1) digits in length.
- shortHintCount = Math.floor(
- (Math.pow(@linkHintCharacters.length, digitsNeeded) - linkCount) /
- @linkHintCharacters.length)
- longHintCount = linkCount - shortHintCount
-
- hintStrings = []
-
- if (digitsNeeded > 1)
- for i in [0...shortHintCount]
- hintStrings.push(numberToHintString(i, @linkHintCharacters, digitsNeeded - 1))
-
- start = shortHintCount * @linkHintCharacters.length
- for i in [start...(start + longHintCount)]
- hintStrings.push(numberToHintString(i, @linkHintCharacters, digitsNeeded))
-
- @shuffleHints(hintStrings, @linkHintCharacters.length)
+ hints = [""]
+ offset = 0
+ while hints.length - offset < linkCount or hints.length == 1
+ hint = hints[offset++]
+ hints.push ch + hint for ch in @linkHintCharacters
+ hints = hints[offset...offset+linkCount]
- #
- # This shuffles the given set of hints so that they're scattered -- hints starting with the same character
- # will be spread evenly throughout the array.
- #
- shuffleHints: (hints, characterSetLength) ->
- buckets = ([] for i in [0...characterSetLength] by 1)
- for hint, i in hints
- buckets[i % buckets.length].push(hint)
- result = []
- for bucket in buckets
- result = result.concat(bucket)
- result
+ # Shuffle the hints so that they're scattered; hints starting with the same character and short hints are
+ # spread evenly throughout the array.
+ return hints.sort().map (str) -> str.reverse()
getMatchingHints: (hintMarkers) ->
matchString = @hintKeystrokeQueue.join ""
@@ -505,7 +480,12 @@ class FilterHints
@labelMap[forElement] = labelText
generateHintString: (linkHintNumber) ->
- numberToHintString linkHintNumber, @linkHintNumbers.toUpperCase()
+ base = @linkHintNumbers.length
+ hint = []
+ while 0 < linkHintNumber
+ hint.push @linkHintNumbers[Math.floor linkHintNumber % base]
+ linkHintNumber = Math.floor linkHintNumber / base
+ hint.reverse().join ""
generateLinkText: (element) ->
linkText = ""
@@ -637,29 +617,6 @@ spanWrap = (hintString) ->
innerHTML.push("<span class='vimiumReset'>" + char + "</span>")
innerHTML.join("")
-#
-# Converts a number like "8" into a hint string like "JK". This is used to sequentially generate all of the
-# hint text. The hint string will be "padded with zeroes" to ensure its length is >= numHintDigits.
-#
-numberToHintString = (number, characterSet, numHintDigits = 0) ->
- base = characterSet.length
- hintString = []
- remainder = 0
- loop
- remainder = number % base
- hintString.unshift(characterSet[remainder])
- number -= remainder
- number /= Math.floor(base)
- break unless number > 0
-
- # Pad the hint string we're returning so that it matches numHintDigits.
- # Note: the loop body changes hintString.length, so the original length must be cached!
- hintStringLength = hintString.length
- for i in [0...(numHintDigits - hintStringLength)] by 1
- hintString.unshift(characterSet[0])
-
- hintString.join("")
-
# Suppress all keyboard events until the user stops typing for sufficiently long.
class TypingProtector extends Mode
constructor: (delay, callback) ->
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 781223b1..e041245d 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -217,7 +217,6 @@ window.addEventListener "hashchange", onFocus
initializeOnDomReady = ->
# Tell the background page we're in the dom ready state.
chrome.runtime.connect({ name: "domReady" })
- CursorHider.init()
# We only initialize the vomnibar in the tab's main frame, because it's only ever opened there.
Vomnibar.init() if DomUtils.isTopFrame()
HUD.init()
@@ -836,40 +835,6 @@ toggleHelpDialog = (html, fid) ->
else
showHelpDialog(html, fid)
-CursorHider =
- #
- # Hide the cursor when the browser scrolls, and prevent mouse from hovering while invisible.
- #
- cursorHideStyle: null
- isScrolling: false
-
- onScroll: (event) ->
- CursorHider.isScrolling = true
- unless CursorHider.cursorHideStyle.parentElement
- document.head.appendChild CursorHider.cursorHideStyle
-
- onMouseMove: (event) ->
- if CursorHider.cursorHideStyle.parentElement and not CursorHider.isScrolling
- CursorHider.cursorHideStyle.remove()
- CursorHider.isScrolling = false
-
- init: ->
- # Temporarily disabled pending consideration of #1359 (in particular, whether cursor hiding is too fragile
- # as to provide a consistent UX).
- return
-
- # Disable cursor hiding for Chrome versions less than 39.0.2171.71 due to a suspected browser error.
- # See #1345 and #1348.
- return unless Utils.haveChromeVersion "39.0.2171.71"
-
- @cursorHideStyle = DomUtils.createElement "style"
- @cursorHideStyle.innerHTML = """
- body * {pointer-events: none !important; cursor: none !important;}
- body, html {cursor: none !important;}
- """
- window.addEventListener "mousemove", @onMouseMove
- window.addEventListener "scroll", @onScroll
-
initializePreDomReady()
DomUtils.documentReady initializeOnDomReady
DomUtils.documentReady registerFrame
diff --git a/lib/utils.coffee b/lib/utils.coffee
index b69b926b..c255102e 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -281,6 +281,7 @@ Array.copy = (array) -> Array.prototype.slice.call(array, 0)
String::startsWith = (str) -> @indexOf(str) == 0
String::ltrim = -> @replace /^\s+/, ""
String::rtrim = -> @replace /\s+$/, ""
+String::reverse = -> @split("").reverse().join ""
globalRoot = window ? global
globalRoot.extend = (hash1, hash2) ->
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee
index e814ec76..1d4703c1 100644
--- a/tests/dom_tests/dom_tests.coffee
+++ b/tests/dom_tests/dom_tests.coffee
@@ -149,10 +149,8 @@ context "Alphabetical link hints",
document.getElementById("test-div").innerHTML = ""
should "label the hints correctly", ->
- # TODO(philc): This test verifies the current behavior, but the current behavior is incorrect.
- # The output here should be something like aa, ab, b.
hintMarkers = getHintMarkers()
- expectedHints = ["aa", "ba", "ab"]
+ expectedHints = ["aa", "b", "ab"]
for hint, i in expectedHints
assert.equal hint, hintMarkers[i].hintString