hinting: add "numeric" name mode

This is similar to setting "hintchars" to "1234567890", but
ends up with more predictable and stable hints (see the
included documentation).

Setting "hintfiltermode" to "vimperator-reflow" and
"hintnames" to "numeric" provides more or less the same
experience that pentadactyl did.
This commit is contained in:
Jeff King 2018-03-17 00:40:23 -04:00
parent 87529877b9
commit a9dd3ca25f
2 changed files with 24 additions and 2 deletions

View file

@ -2434,12 +2434,21 @@ import * as hinting from "./hinting_background"
- "hintchars": "hjklasdfgyuiopqwertnmzxcvb"
- "hintfiltermode": "simple" | "vimperator" | "vimperator-reflow"
- "relatedopenpos": "related" | "next" | "last"
- "hintnames": "short" | "uniform"
- "hintnames": "short" | "uniform" | "numeric"
With "short" names, Tridactyl will generate short hints that
are never prefixes of each other. With "uniform", Tridactyl
will generate hints of uniform length. In either case, the
hints are generated from the set in "hintchars".
With "numeric" names, hints are always assigned using
sequential integers, and "hintchars" is ignored. This has the
disadvantage that some hints are prefixes of others (and you
need to hit space or enter to select such a hint). But it has
the advantage that the hints tend to be more predictable
(e.g., a news site will have the same hints for its
boilerplate each time you visit it, even if the number of
links in the main body changes).
*/
//#background
export function hint(option?: string, selectors?: string, ...rest: string[]) {

View file

@ -120,7 +120,12 @@ function defaultHintFilter() {
}
function defaultHintChars() {
return config.get("hintchars")
switch (config.get("hintnames")) {
case "numeric":
return "1234567890"
default:
return config.get("hintchars")
}
}
/** An infinite stream of hints
@ -179,11 +184,19 @@ function* hintnames_uniform(
}
}
function* hintnames_numeric(n: number): IterableIterator<string> {
for (let i = 1; i <= n; i++) {
yield String(i)
}
}
function* hintnames(
n: number,
hintchars = defaultHintChars(),
): IterableIterator<string> {
switch (config.get("hintnames")) {
case "numeric":
yield* hintnames_numeric(n)
case "uniform":
yield* hintnames_uniform(n, hintchars)
default: