-
Notifications
You must be signed in to change notification settings - Fork 22
feat: Add find-in-page functionality and shortcuts #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: Add find-in-page functionality and shortcuts #154
Conversation
Co-authored-by: meta.alex.r <meta.alex.r@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| // Enable native find-in-page functionality with keyboard shortcuts | ||
| let findActive = false; | ||
|
|
||
| mainWindow.webContents.on("before-input-event", (event, input) => { | ||
| // Handle Cmd/Ctrl+F to start find | ||
| if (input.type === "keyDown" && input.key === "f" && (input.control || input.meta)) { | ||
| event.preventDefault(); | ||
| // Start find with empty string to show the find interface | ||
| mainWindow?.webContents.findInPage(""); | ||
| findActive = true; | ||
| } | ||
| // Handle Escape to stop find | ||
| else if (input.type === "keyDown" && input.key === "Escape" && findActive) { | ||
| event.preventDefault(); | ||
| mainWindow?.webContents.stopFindInPage("clearSelection"); | ||
| findActive = false; | ||
| } | ||
| // Handle Enter for find next (when find is active) | ||
| else if (input.type === "keyDown" && input.key === "Enter" && findActive && !input.shift) { | ||
| event.preventDefault(); | ||
| mainWindow?.webContents.findInPage("", { forward: true, findNext: true }); | ||
| } | ||
| // Handle Shift+Enter for find previous (when find is active) | ||
| else if (input.type === "keyDown" && input.key === "Enter" && findActive && input.shift) { | ||
| event.preventDefault(); | ||
| mainWindow?.webContents.findInPage("", { forward: false, findNext: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find shortcut never gathers search text and hijacks Enter
The new before-input-event handler sets findActive on every Cmd/Ctrl+F and then preventDefaults any subsequent Enter press while findActive is true, routing it to webContents.findInPage("", {findNext:true}). Electron does not show a native find UI and an empty string uses the previous selection, so most users never enter a search term and nothing is found. After a single Ctrl+F, the window effectively loses all Enter behaviour (e.g. submitting forms or triggering buttons) until Escape is pressed, because the handler intercepts the key even though no search is in progress. The feature therefore both fails to provide “find in page” and breaks normal keyboard interaction.
Useful? React with 👍 / 👎.
Fixes #32