Repository navigation
Anchor the #endregion folding marker - #261
Open
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
Open
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
Conversation
The marker test reads /^\s*#(region\b)|(endregion\b)/, and alternation binds looser than the anchor, so `^\s*#` applies only to the first branch. Any comment containing the word "endregion" anywhere matched the second one. An open #region was therefore closed at that comment instead of at its real marker, and the comment lost its own folding range in the process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
htmlFolding.tsdetects region markers with:Alternation binds looser than the anchor, so this reads as
(^\s*#region\b)or(endregion\b)— the second branch is unanchored and matches the word anywhere in a comment.Effect
Measured with
getFoldingRangeson the built library:#region… a harmless multi-line comment …#endregion{3-5 comment}, {0-7 region}✓{0-3 region}✗{0-4 comment}✓[]✗Two things go wrong at once. The open
#regionis closed at the prose comment instead of at its real marker, so the fold covers the wrong span; and because that comment was consumed as a marker, it also loses its own folding range.An HTML comment that documents region markers — or any prose that happens to contain the word — is enough to trigger it.
Fix
Group the alternation so the anchor covers both branches:
Capture-group numbering is unchanged, so the
m[1]/m[2]branches below need no edit.Test plan
src/test/folding.test.tsbeside the existingFold regions: a region whose body contains a comment mentioning endregion, and a standalone comment containing the word.node --test ./lib/esm/test/*.test.js→ 178 passing (176 before).htmlFolding.tsfails both new tests.npm run lint→ clean.