Skip to content
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

Windows/macOS: Resolves #7520: Search field doesn't get focus when pressing Ctrl+F #7529

Conversation

betty-alagwu
Copy link
Contributor

@betty-alagwu betty-alagwu commented Dec 24, 2022

Fixes #7520

Solution

I fixed this by adding a useEffect that auto focuses the search input after it is opened from the command execution.

Electron.-.Joplin.DEV.-._Users_macbookair_.config_joplindev-desktop.-.24.December.2022.mp4

@github-actions
Copy link
Contributor

github-actions bot commented Dec 24, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@betty-alagwu
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@betty-alagwu
Copy link
Contributor Author

recheck

@@ -13,7 +13,6 @@ export const runtime = (comp: any): CommandRuntime => {
comp.editorRef.current.execCommand({ name: 'search' });
} else {
comp.setShowLocalSearch(true);
if (comp.noteSearchBarRef.current) comp.noteSearchBarRef.current.wrappedInstance.focus();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you made focus() public, does it work if you just replace this with comp.noteSearchBarRef.current.focus()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurent22 no it doesn't. We can't focus immediately after calling comp.setShowLocalSearch(true) because React needs some time to rerender, so I used the useEffect instead and called noteSearchBarRef.current.focus() in the useEffect.

@sanskarfc
Copy link

Just another caveat...

After pressing Ctrl + F once, my cursor moves in the local search area, but if I move my cursor to the note and press Ctrl + F once again (while in note area with the local search already open), the cursor doesn't move back into the local search.

@betty-alagwu
Copy link
Contributor Author

Thank you @sanskarfc . I pushed a change to address this. Thank you @laurent22 also for your review. Looking forward to any additional feedback.

@laurent22 laurent22 merged commit 5fb01b5 into laurent22:dev Dec 30, 2022
@laurent22
Copy link
Owner

Looks good now, thanks for fixing this!

@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search field doesn't get focus when pressing Ctrl+F
3 participants