Skip to content

Commit fa5840a

Browse files
committed
feat(hint): add numeric label generator helper
The function is only a few lines, but we can help out users by providing a stock implementation. Note that we ignore hint_chars here! You might think that we could provide just a "sequential" generator that would turn an alphabet like "abc" into: a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, ... and then feed it the numeric digits via hint_chars. But that is not quite how numbers work. If the alphabet is "1234567890", then we get "0" instead of "10" as the tenth label, and "10" as the twentieth. If you instead use "0123456789", then we start with "0" and get "01", "02", etc, instead of the teens. You'd have to be smart about how zeroes are handled, at which point it is easier to just have a custom generator that simply counts.
1 parent b8a509e commit fa5840a

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/glide/browser/base/content/browser.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,14 @@ function make_glide_api(): typeof glide {
19011901
label_prefix_free(hints): string[] {
19021902
return GlideHints.hint_label_prefix_free(hints.length);
19031903
},
1904+
1905+
label_numeric(hints): string[] {
1906+
var ret = [];
1907+
for (var i = 1; i <= hints.length; i++) {
1908+
ret.push(i.toString());
1909+
}
1910+
return ret;
1911+
},
19041912
},
19051913

19061914
addons: {

src/glide/browser/base/content/glide.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ declare global {
934934
* - `glide.hints.label_prefix_free`: Generate prefix-free
935935
* combinations of the characters in [hint_chars](#glide.o.hint_chars).
936936
* This is the default.
937+
*
938+
* - `glide.hints.label_numeric`: Generate sequential numeric labels,
939+
* starting at `1` and counting up. Ignores [hint_chars](#glide.o.hint_chars).
937940
*/
938941
hint_label_generator: (GlideResolvedHint[]) => string[];
939942
};

src/glide/browser/base/content/test/hints/browser_hints.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,20 @@ add_task(async function test_hint_generator_config() {
295295
await keys("<esc>");
296296
});
297297
});
298+
299+
add_task(async function test_numeric_hint_generator() {
300+
await GlideTestUtils.reload_config(function _() {
301+
glide.o.hint_label_generator = glide.hints.label_numeric;
302+
});
303+
304+
await BrowserTestUtils.withNewTab(FILE, async _browser => {
305+
await keys("f");
306+
await wait_for_hints();
307+
308+
const hints = GlideHints.get_active_hints();
309+
is(hints[0]?.label, "1");
310+
is(hints[1]?.label, "2");
311+
is(hints[9]?.label, "10");
312+
await keys("<esc>");
313+
});
314+
});

src/glide/docs/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ your own function or use an included one:
227227
combinations of the characters in [hint_chars](#glide.o.hint_chars).
228228
This is the default.
229229

230+
- `glide.hints.label_numeric`: Generate sequential numeric labels,
231+
starting at `1` and counting up. Ignores [hint_chars](#glide.o.hint_chars).
232+
230233
## `glide.bo: Partial<glide.Options>` {% id="glide.bo" %}
231234

232235
Set buffer specific options.

0 commit comments

Comments
 (0)