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

Desktop: Resolves #9927: Beta editor: Fix search results not highlighted #9928

Conversation

personalizedrefrigerator
Copy link
Collaborator

@personalizedrefrigerator personalizedrefrigerator commented Feb 12, 2024

Summary

  • Updates CodeMirror5Emulation such that Joplin's CodeMirror 5 search highlighting works with CodeMirror 6.
  • For now, search results aren't marked on the scrollbar — this might be something we need to implement ourselves (see this post on the CM6 forum).

Fixes #9927.

Testing

  1. Enable the CodeMirror 5 editor

  2. Search for a full-word term known to be present in multiple notes (e.g. "references")

  3. Change the search term to work around Desktop: Search matches sometimes not shown in CM5 editor #9926

  4. Verify that matches are shown on the scrollbar

  5. Verify that matches are highlighted in both the editor and viewer

  6. Enable the CodeMirror 6 editor

  7. Search for "references"

  8. Change the search term to work around Desktop: Search matches sometimes not shown in CM5 editor #9926

  9. Verify that matches are highlighted in both the editor and viewer

This has been tested successfully on Ubuntu 23.10.

@@ -172,7 +176,7 @@ export default function useEditorSearch(CodeMirror: any) {
// These operations are pretty slow, so we won't add use them until the user
// has finished typing, 500ms is probably enough time
const timeout = shim.setTimeout(() => {
const scrollMarks = this.showMatchesOnScrollbar(searchTerm, true, 'cm-search-marker-scrollbar');
const scrollMarks = this.showMatchesOnScrollbar?.(searchTerm, true, 'cm-search-marker-scrollbar');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At present, showMatchesOnScrollbar is only implemented for CodeMirror 5. As per this discussion thread, we'll likely need to implement this ourselves.

renderedBody: RenderedBody;
}

const useEditorSearchHandler = (props: Props) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

useEditorSearchHandler was originally part of v5/CodeMirror.tsx.

}

if (match) {
if (scrollTo) {
if (withSelection) {
cm.setSelection(match.from, match.to);
} else {
cm.scrollTo(match);
cm.scrollIntoView(match);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to the CodeMirror documentation, .scrollTo takes two arguments, while scrollIntoView can take an object with the same type as match.

As such, I suspect we were calling scrollTo incorrectly.

@laurent22
Copy link
Owner

@personalizedrefrigerator there's one conflict here as well

@laurent22
Copy link
Owner

Sorry, a few more conflicts now

@laurent22
Copy link
Owner

It's complaining about a spelling mistake:

2024-03-02T19:22:58.9062623Z /home/runner/work/joplin/joplin/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.test.ts:135:58 - Unknown word (Testst)

@laurent22 laurent22 merged commit 20f8bb7 into laurent22:dev Mar 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Desktop: Joplin search terms not highlighted in beta CM6 editor or viewer
2 participants