Skip to content

Commit 48e4bb6

Browse files
committed
fix: reset partial key sequence on click/scroll
1 parent 1993ba2 commit 48e4bb6

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class GlideBrowserClass {
100100
document!.addEventListener("keydown", this.#on_keydown.bind(this), true);
101101
document!.addEventListener("keypress", this.#on_keypress.bind(this), true);
102102
document!.addEventListener("keyup", this.#on_keyup.bind(this), true);
103+
document!.addEventListener("mousedown", this.#on_mousedown.bind(this), true);
104+
document!.addEventListener("wheel", this.#on_wheel.bind(this), true);
103105
window.addEventListener("MozDOMFullscreen:Entered", this.#on_fullscreen_enter.bind(this), true);
104106
window.addEventListener("MozDOMFullscreen:Exited", this.#on_fullscreen_exit.bind(this), true);
105107

@@ -1790,6 +1792,41 @@ class GlideBrowserClass {
17901792
}
17911793
}
17921794

1795+
async #on_mousedown(event: MouseEvent) {
1796+
if ((event.target as any).$glide_hack_click_from_hint) {
1797+
return;
1798+
}
1799+
const has_partial = this.key_manager.has_partial_mapping;
1800+
if (!has_partial) {
1801+
return;
1802+
}
1803+
const mode = this.state.mode;
1804+
this._log.debug("mousedown event", "resetting key sequence");
1805+
this.key_manager.reset_sequence();
1806+
this.#display_keyseq([]);
1807+
this.#invoke_keystatechanged_autocmd({
1808+
mode,
1809+
sequence: [],
1810+
partial: false,
1811+
});
1812+
}
1813+
1814+
async #on_wheel(_event: WheelEvent) {
1815+
const has_partial = this.key_manager.has_partial_mapping;
1816+
if (!has_partial) {
1817+
return;
1818+
}
1819+
const mode = this.state.mode;
1820+
this._log.debug("scroll event", "resetting key sequence");
1821+
this.key_manager.reset_sequence();
1822+
this.#display_keyseq([]);
1823+
this.#invoke_keystatechanged_autocmd({
1824+
mode,
1825+
sequence: [],
1826+
partial: false,
1827+
});
1828+
}
1829+
17931830
/**
17941831
* Returns the Glide JSActor for the currently focused frame.
17951832
*

src/glide/browser/base/content/test/mode/browser_keyseq_display.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,40 @@ add_task(async function test_keyseq_display_without_toolbar_button() {
120120
// Restore the button for other tests
121121
document!.body!.appendChild(original_button!);
122122
});
123+
124+
add_task(async function test_click_resets_partial_leader_sequence() {
125+
await reload_config(function _() {});
126+
await keys("<escape>");
127+
await keys("<leader>");
128+
await sleep_frames(2);
129+
is(GlideBrowser.key_manager.has_partial_mapping, true, "Leader key should start partial sequence");
130+
is(GlideBrowser.key_manager.current_sequence.join(""), "<Space>", "Sequence should contain space");
131+
132+
const body = document!.querySelector("body")!;
133+
EventUtils.synthesizeMouse(body, 100, 100, {}, window);
134+
await sleep_frames(2);
135+
is(GlideBrowser.key_manager.has_partial_mapping, false, "Click should reset partial sequence");
136+
is(GlideBrowser.key_manager.current_sequence.length, 0, "Sequence should be empty after click");
137+
});
138+
139+
add_task(async function test_wheel_resets_partial_leader_sequence() {
140+
await reload_config(function _() {});
141+
await BrowserTestUtils.withNewTab(
142+
"http://mochi.test:8888/browser/glide/browser/base/content/test/mode/key_test.html",
143+
async () => {
144+
await keys("<escape>");
145+
GlideBrowser.key_manager.reset_sequence();
146+
await keys("<leader>");
147+
await sleep_frames(2);
148+
149+
is(GlideBrowser.key_manager.has_partial_mapping, true, "Leader key should start partial sequence");
150+
EventUtils.synthesizeWheel(document!.querySelector("body")!, 100, 100, {
151+
deltaY: 100,
152+
}, window);
153+
await sleep_frames(2);
154+
155+
is(GlideBrowser.key_manager.has_partial_mapping, false, "Wheel should reset partial sequence");
156+
is(GlideBrowser.key_manager.current_sequence.length, 0, "Sequence should be empty after wheel");
157+
},
158+
);
159+
});

0 commit comments

Comments
 (0)