Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/glide/browser/base/content/browser.mts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class GlideBrowserClass {
document!.addEventListener("keydown", this.#on_keydown.bind(this), true);
document!.addEventListener("keypress", this.#on_keypress.bind(this), true);
document!.addEventListener("keyup", this.#on_keyup.bind(this), true);
document!.addEventListener("mousedown", this.#on_mousedown.bind(this), true);
document!.addEventListener("wheel", this.#on_wheel.bind(this), true);
window.addEventListener("MozDOMFullscreen:Entered", this.#on_fullscreen_enter.bind(this), true);
window.addEventListener("MozDOMFullscreen:Exited", this.#on_fullscreen_exit.bind(this), true);

Expand Down Expand Up @@ -1790,6 +1792,41 @@ class GlideBrowserClass {
}
}

async #on_mousedown(event: MouseEvent) {
if ((event.target as any).$glide_hack_click_from_hint) {
return;
}
const has_partial = this.key_manager.has_partial_mapping;
if (!has_partial) {
return;
}
const mode = this.state.mode;
this._log.debug("mousedown event", "resetting key sequence");
this.key_manager.reset_sequence();
this.#display_keyseq([]);
this.#invoke_keystatechanged_autocmd({
mode,
sequence: [],
partial: false,
});
}

async #on_wheel(_event: WheelEvent) {
const has_partial = this.key_manager.has_partial_mapping;
if (!has_partial) {
return;
}
const mode = this.state.mode;
this._log.debug("scroll event", "resetting key sequence");
this.key_manager.reset_sequence();
this.#display_keyseq([]);
this.#invoke_keystatechanged_autocmd({
mode,
sequence: [],
partial: false,
});
}

/**
* Returns the Glide JSActor for the currently focused frame.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,40 @@ add_task(async function test_keyseq_display_without_toolbar_button() {
// Restore the button for other tests
document!.body!.appendChild(original_button!);
});

add_task(async function test_click_resets_partial_leader_sequence() {
await reload_config(function _() {});
await keys("<escape>");
await keys("<leader>");
await sleep_frames(2);
is(GlideBrowser.key_manager.has_partial_mapping, true, "Leader key should start partial sequence");
is(GlideBrowser.key_manager.current_sequence.join(""), "<Space>", "Sequence should contain space");

const body = document!.querySelector("body")!;
EventUtils.synthesizeMouse(body, 100, 100, {}, window);
await sleep_frames(2);
is(GlideBrowser.key_manager.has_partial_mapping, false, "Click should reset partial sequence");
is(GlideBrowser.key_manager.current_sequence.length, 0, "Sequence should be empty after click");
});

add_task(async function test_wheel_resets_partial_leader_sequence() {
await reload_config(function _() {});
await BrowserTestUtils.withNewTab(
"http://mochi.test:8888/browser/glide/browser/base/content/test/mode/key_test.html",
async () => {
await keys("<escape>");
GlideBrowser.key_manager.reset_sequence();
await keys("<leader>");
await sleep_frames(2);

is(GlideBrowser.key_manager.has_partial_mapping, true, "Leader key should start partial sequence");
EventUtils.synthesizeWheel(document!.querySelector("body")!, 100, 100, {
deltaY: 100,
}, window);
await sleep_frames(2);

is(GlideBrowser.key_manager.has_partial_mapping, false, "Wheel should reset partial sequence");
is(GlideBrowser.key_manager.current_sequence.length, 0, "Sequence should be empty after wheel");
},
);
});