fix: remove all manual folding ranges when selection is empty - #304793
Conversation
When editor.removeManualFoldingRanges is invoked with an empty selection (just a cursor, no text selected), remove all manual folding ranges in the document instead of only removing ranges intersecting the cursor line. This makes it easy to clear broken manual folding ranges without having to select all text first. When text is explicitly selected, the existing behavior of only removing manual ranges intersecting the selection is preserved. Closes microsoft#266597
When cursor is on a manual folding range, remove only the innermost one. When cursor is NOT on any manual range, remove all manual ranges. This addresses both microsoft#266597 and microsoft#212599 in a single approach. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Updated the implementation based on RedCMD (@RedCMD)'s suggestion from #266597. The combined approach now:
This addresses both #266597 and #212599 in a single, consistent behavior. PR #304808 is now superseded by this approach. |
|
Also please add tests. |
Address review feedback: move the "find innermost manual range at cursor, or remove all" logic from RemoveFoldRangeFromSelectionAction.invoke() into FoldingModel.removeManualRanges(), since that action is the only caller. The action now simply passes raw selection ranges as before. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover three scenarios: - Cursor on a manual range removes only the innermost manual range - Cursor not on any manual range removes all manual ranges - Selection range removes only intersecting manual ranges Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Added tests for
|
There was a problem hiding this comment.
Pull request overview
This PR changes FoldingModel.removeManualRanges (used by the editor.removeManualFoldingRanges command) so that a cursor-only invocation is handled specially. When a range spans a single line, it now walks up from the innermost folding region at that line to find the nearest manual (non-provider) range and removes only that one (fixing #212599, where the outer range was removed instead of the innermost). If no manual range contains the cursor, it removes every manual range in the document (fixing #266597). Multi-line selections keep the previous "remove intersecting manual ranges" behavior.
Changes:
- Added innermost-manual-range resolution and an "remove all manual ranges" fallback for single-line ranges in
removeManualRanges. - Reworked the
intersectshelper to operate on the resolved ranges instead of the raw input ranges. - Added three unit tests covering cursor-on-manual, cursor-not-on-manual, and multi-line selection cases.
Show a summary per file
| File | Description |
|---|---|
| src/vs/editor/contrib/folding/browser/foldingModel.ts | Adds single-line (cursor) handling: remove innermost manual range, else remove all manual ranges; intersects now uses resolved ranges. |
| src/vs/editor/contrib/folding/test/browser/foldingModel.test.ts | Adds tests for innermost removal, remove-all fallback, and multi-line selection behavior; imports FoldingRegions, FoldRange, FoldSource. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
72b683b
|
Addressed the review feedback in
Validation: all 21 tests in |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dfce22a
Summary
When invoking
editor.removeManualFoldingRangeswith an empty selection (cursor only):When text is explicitly selected, the existing behavior is preserved — only manual ranges intersecting the selection are removed.
This combined approach follows RedCMD (@RedCMD)'s suggestion from #266597 to detect whether a range intersects the empty selection, and also satisfies Martin Aeschlimann (@aeschli)'s request to support empty selection for removing all manual folding ranges.
Fixes #266597
Fixes #212599
Test plan