Skip to content

Skip empty find match at the end of previous match (Part 2 for issue #116445) #116821

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

IllusionMH
Copy link
Contributor

@IllusionMH IllusionMH commented Feb 17, 2021

This PR is related to #116445

JS engine will provide empty string matches at the end of non-empty matches if RegExp has zero or more quantifier (*)

[...'10.243.30.10'.matchAll(/\d*/g)]
[    
    ["10", index: 0, input: "10.243.30.10", groups: undefined],
    ["", index: 2, input: "10.243.30.10", groups: undefined],
    ["243", index: 3, input: "10.243.30.10", groups: undefined],
    ["", index: 6, input: "10.243.30.10", groups: undefined],
    ["30", index: 7, input: "10.243.30.10", groups: undefined],
    ["", index: 9, input: "10.243.30.10", groups: undefined],
    ["10", index: 10, input: "10.243.30.10", groups: undefined],
    ["", index: 12, input: "10.243.30.10", groups: undefined]
]

While currently VS Code provides same results as JS (which is expected), these empty matches do not provide any useful value and may be confusing to users (see linked issue).
Moreover it's hard to observe these matches - Alt+Enter will select all ranges, but because cursors at the end of these empty ranges overlap with end of previous selections they are basically ignored.

Moreover actions triggered on Previous/Next match will intentionally skip this kind of matches which leads to strange values for current selection index during navigation "1 of 9", "3 of 9", "4 of 9", "6 of 9" etc.

if (forceMove && nextMatch && nextMatch.range.isEmpty() && nextMatch.range.getStartPosition().equals(position)) {

This change updates search model in a way that won't produce empty ranges at the end of previous matches. Empty matches that are not overlap with non-empty matches are preserved as previously.

@rebornix would love to hear your feedback about this proposal.

P.S. This is second part of the fix for #116445 which provides improvement for match behavior.
Part 1 for navigation fix (do not skip non-empty matches in same line) submitted as draft as well - #116823

@rebornix rebornix added this to the On Deck milestone Oct 12, 2021
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