Fix ViewModel issue where all lines were hidden#296709
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an edge case in the editor ViewModel’s constant-time prefix sum implementation where getIndexOf could return an invalid index (e.g. when all values are zero), which can result in all lines being treated as hidden.
Changes:
- Fix
ConstantTimePrefixSumComputer.getIndexOfto handle sums that are not present in_indexBySum(notably when total sum is 0). - Fix
_ensureValidtrimming logic to avoid invalid_indexBySum.lengthwhen the values array is empty. - Expand the prefix sum test suite to run the same behavioral assertions against both
PrefixSumComputerandConstantTimePrefixSumComputer.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/editor/test/common/viewModel/prefixSumComputer.test.ts | Refactors/expands tests to validate both prefix-sum implementations across many scenarios (zeroes, inserts/removes, mutations). |
| src/vs/editor/common/model/prefixSumComputer.ts | Adds a safety fallback in ConstantTimePrefixSumComputer.getIndexOf and fixes _indexBySum.length trimming for empty inputs. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… areas When an edit (delete/undo) removes or merges the only visible line(s) into hidden lines, the view model could end up with zero visible lines, causing downstream crashes (e.g. 'Not supported' from HiddenModelLineProjection). The safety check in acceptVersionId only caught the case where exactly 1 hidden line remained. Generalize it to detect when getViewLineCount() === 0 and minimally restore visibility by making just the first line visible, preserving the caller's intended hidden areas as much as possible.
…ible lines) is now fixed at the source
When hidden area decorations drift via AlwaysGrowsWhenTypingAtEdges stickiness, _constructLines(resetHiddenAreas=false) — triggered by tab size or wrapping changes — can rebuild projections with all lines hidden. Extract _ensureAtLeastOneVisibleLine() shared by both _constructLines and acceptVersionId.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
rebornix
approved these changes
Feb 21, 2026
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.
Fixes #293365
ConstantTimePrefixSumComputerto better handle the case where all values are zeroes.