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

Find/Replace Overlay: highlight regex matches toggle #2679

Open
Tracked by #2021
nlisker opened this issue Jan 9, 2025 · 6 comments
Open
Tracked by #2021

Find/Replace Overlay: highlight regex matches toggle #2679

nlisker opened this issue Jan 9, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@nlisker
Copy link

nlisker commented Jan 9, 2025

When writing a regex in the Find field, it's useful to see the matches in the selected region (or the whole file if no region is selected) in real-time, much like ctrl+F works in browsers. This avoids repeatedly clicking on Find to see if the regex works as intended. Because for large files this can be costly, it should be enabled via a toggle. Matched regions can be indicated with a background highlight, just like Toggle Mark Occurrences works.

This is also relevant for the "old" Find/Replace dialog.

@nlisker nlisker added the enhancement New feature or request label Jan 9, 2025
@HeikoKlare
Copy link
Contributor

I agree that this would be quite helpful to test regular expressions.

The proposal has some overlap with:

That one proposes to mark occurrences of a search string inside the document while typing. When this is also applied to regex searches (as it should be by default) and if it is also limited to the selected region (in case such a region is defined), it should cover this proposal completely, if I understand it correctly.

Note that we merged a PR last week, which also partly covers this proposal:

Search-as-you-type is now also applied in regex mode, so you can already use this to test a regex, but it will only give you a single match and not all matches in the selected region. But is of course also restricted to the selected region.

@jukzi
Copy link
Contributor

jukzi commented Jan 10, 2025

+1

@nlisker
Copy link
Author

nlisker commented Jan 10, 2025

@HeikoKlare I updated to the latest build and I can see the change, it's certainly better. Apart from finding only the first search result, I found it odd that the highlight is actually a selection, so if I leave the Find/Replace focus my typing replaces the selection. I would have thought a "passive" highlight like Mark Occurrences would be more apt. Is there a reason to use selection?

@HeikoKlare
Copy link
Contributor

I would have thought a "passive" highlight like Mark Occurrences would be more apt. Is there a reason to use selection?

Considering the use case in an isolated way, I agree that one might argue for just highlighting a result instead of selecting it.
But since the use case is embedded into the find/replace overlay/dialog, which also providing several further use cases to which you would expect some consisistency, I would rather ask the opposite: why should, in this case, only a highlighting be performed, without any selection? When using search-as-you-type (without regex mode), the match is selected. If I am not mistaken, this has even been the case for the find/replace dialog for years (called "incremental" in that dialog). This incremental mode was just not available when when searching in regex mode.
I would find it quite unexpected if the search would now behave differently when run in regex mode than when it runs in non-regex mode. Making the behavior consistent was one of the reasons for enabling search-as-you-type for regex mode as well and the proposed behavior would, in my opinion, conflict with that goal.

In addition, the current behavioral consistency of the different modes mentioned above does not require the code to distinguish between different modes but mostly handles everything in the same way. Having regex mode behave different than other search modes would lead to additional implementation efforts and complexity in the code.

@nlisker
Copy link
Author

nlisker commented Jan 13, 2025

I didn't notice that in the new Find/Replace there is a search-as-you-type implemented already for plain text. Since that is the case, the selection is fine. I was just not sure what the benefit of selection is when you have the option to replace that text with the Replace function.

@HeikoKlare
Copy link
Contributor

I see. The search-as-you-type just performs an ordinary selection, line when performing an explicit find operation (via the find foward/backward buttons). This is even a prerequisite for performing a replace operation. If there was no preceding find operation (including the selection of the match), you cannot execute a replace operation.

This behavior is now also consistent to other tools (like VS Code and IntelliJ), which also have search-as-you-type enabled by default, that search performs selections, which are preserved when leaving the find UI, and the operate in the same way for normal and regex search. So users should experience quite similar behavior in different tools, allowing to use the same workflows without adapting to the tool they are using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants