Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix(find): let the page handle Ctrl+F before Pake's find panel
Tw9349084531f87e
diff --git a/src-tauri/src/inject/find.js b/src-tauri/src/inject/find.jsindex e2712a56..dff26482 100644--- a/src-tauri/src/inject/find.js+++ b/src-tauri/src/inject/find.js@@ -698,14 +698,19 @@return "";}+ // The page gets the shortcut first: listening on window in the bubble phase runs after the+ // page's own element and document handlers, and a page with its own find (Notion, Google+ // Docs) calls preventDefault, so Pake's panel stays out of its way. Propagation is left alone.function handleFindShortcut(event) {+ if (event.defaultPrevented) {+ return;+ }const action = getFindShortcutAction(event);if (!action) {return;}event.preventDefault();- event.stopPropagation();window.pakeFind[action]();}@@ -720,6 +725,6 @@};if (state.enabled) {- document.addEventListener("keydown", handleFindShortcut, true);+ window.addEventListener("keydown", handleFindShortcut);}})();diff --git a/tests/unit/find-shortcuts.test.js b/tests/unit/find-shortcuts.test.jsindex 0e3a2b4c..733d72fb 100644--- a/tests/unit/find-shortcuts.test.js+++ b/tests/unit/find-shortcuts.test.js@@ -208,6 +208,11 @@ function loadFindScript({FILTER_REJECT: 2,},window: {+ listeners: {},+ addEventListener(type, handler, options) {+ this.listeners[type] = this.listeners[type] || [];+ this.listeners[type].push({ handler, options });+ },pakeConfig: { enable_find: enabled },CSSStyleSheet: class CSSStyleSheet {replaceSync(css) {@@ -248,7 +253,7 @@ describe("Find injection", () => {nodes: [createTextNode("Alpha alpha", paragraph)],});- expect(context.document.listeners.keydown).toBeUndefined();+ expect(context.window.listeners.keydown).toBeUndefined();expect(context.window.pakeFind.getState().enabled).toBe(false);expect(context.window.pakeFind.getFindShortcutAction(@@ -271,7 +276,7 @@ describe("Find injection", () => {context.window.pakeFind.next = () => calls.push("next");context.window.pakeFind.previous = () => calls.push("previous");- const [listener] = context.document.listeners.keydown;+ const [listener] = context.window.listeners.keydown;const findEvent = createKeyboardEvent("f", { ctrlKey: true });listener.handler(findEvent);@@ -285,7 +290,22 @@ describe("Find injection", () => {expect(calls).toEqual(["open", "next", "previous"]);expect(findEvent.defaultPrevented).toBe(true);- expect(previousEvent.propagationStopped).toBe(true);+ expect(previousEvent.propagationStopped).toBeFalsy();+ });++ it("lets a page with its own find keep the shortcut", () => {+ const context = loadFindScript({ enabled: true });+ const calls = [];+ context.window.pakeFind.open = () => calls.push("open");++ const [listener] = context.window.listeners.keydown;+ expect(listener.options).toBeUndefined();++ const handled = createKeyboardEvent("f", { ctrlKey: true });+ handled.preventDefault();+ listener.handler(handled);++ expect(calls).toEqual([]);});it("uses the shared style injector for the find panel", () => {@@ -304,7 +324,7 @@ describe("Find injection", () => {const calls = [];context.window.pakeFind.open = () => calls.push("open");- const [listener] = context.document.listeners.keydown;+ const [listener] = context.window.listeners.keydown;listener.handler(createKeyboardEvent("f", { ctrlKey: true }));listener.handler(createKeyboardEvent("f", { metaKey: true }));