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: Fix missed highlighting when using the global search #3717

Merged
merged 2 commits into from
Sep 22, 2020

Conversation

CalebJohn
Copy link
Collaborator

replaces #3622

This solves 3 issues that were present with searching.

  1. As discussed in Desktop: Fixes #3621: Fix highlighting in AceEditor #3622 we don't want to search on every keystroke so this fixes that (CodeMirror.tsx)
  2. There was a race condition where sometimes the editor component wouldn't be ready by the time a search takes place, this adds a new property to the editor component that has the editor search as soon as it's ready. (Editor.tsx)
  3. There was a recently introduced bug that didn't allow the search markers to be cleared once the search bar was empty (BaseApplication.js)

Copy link
Owner

@laurent22 laurent22 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, it makes sense. I just left one comment about a possible missing dependency.

// If there is a currently active search, it's important to re-search the text as the user
// types. However this is slow for performance so we ONLY want it to happen when there is
// a search
const textChanged = props.searchMarkers.keywords.length > 0 && props.content !== previousContent;
Copy link
Owner

Choose a reason for hiding this comment

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

If we need previousContent here, shouldn't it be in the dependency array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good question. previousRenderBody wasn't in there before (hence why I didn't mirror it), and I think maybe it isn't needed.
previousContent only changes when props.content changes (although the change would happen after), because this effect is sensitive to props.content then the effect will trigger with the new props.content and the previous value.
If we add previousContent as a dependency wouldn't that just cause an extra trigger of the effect but it wouldn't have any effect (becuase previousContent now equals props.content)?

Copy link
Owner

Choose a reason for hiding this comment

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

In general I think it's best to have all the dependencies in the array, and then define clearly how it works within the effect (in your case, with the conditional that skip the effect in certain cases). Otherwise we rely on implied behaviour, which might be fine in a small effect, but can be harder to make sense of as it gets more complex.

If it causes an extra trigger that does nothing I think this is acceptable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough. I added previousContent and previousSearchMarkers as dependants and tested to confirm that they don't add additional searches (they don't).

@laurent22 laurent22 mentioned this pull request Sep 14, 2020
29 tasks
@CalebJohn
Copy link
Collaborator Author

@laurent22 suggested changes are made! Should be good to go.

@laurent22 laurent22 changed the base branch from dev to release-1.2 September 22, 2020 12:17
@laurent22 laurent22 merged commit 460a07b into laurent22:release-1.2 Sep 22, 2020
@CalebJohn CalebJohn deleted the fix-highlight branch September 22, 2020 16:24
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.

2 participants