editor: add 'foldedLine' unit to cursorMove command#296106
Merged
alexdima merged 4 commits intomicrosoft:mainfrom Feb 28, 2026
Merged
editor: add 'foldedLine' unit to cursorMove command#296106alexdima merged 4 commits intomicrosoft:mainfrom
alexdima merged 4 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new foldedLine unit to the cursorMove command, enabling vim-like cursor movement that treats each folded region as a single step. This addresses a long-standing feature request (#81498) for extensions like VSCodeVim to properly handle fold navigation.
Changes:
- Adds
FoldedLineenum value toCursorMove.UnitandCursorMove.RawUnit - Implements
_moveDownByFoldedLinesand_moveUpByFoldedLinesmethods that skip over folded regions while moving by logical lines - Updates command metadata and documentation to include the new
foldedLineunit - Adds comprehensive test suite covering fold skipping behavior, multi-line folds, count-based movements, and boundary conditions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/vs/editor/common/cursor/cursorMoveCommands.ts | Implements core fold-aware cursor movement logic, adds enum values, updates command schema and documentation |
| src/vs/editor/test/browser/controller/cursorMoveCommand.test.ts | Adds comprehensive test suite for foldedLine unit with 6 test cases covering various scenarios |
Author
|
@microsoft-github-policy-service agree |
405c4d9 to
13f8179
Compare
Add a new 'foldedLine' movement unit to the `cursorMove` command that moves by model lines while treating each folded region as a single step. When moving down/up by 'wrappedLine' the cursor skips folds naturally because it operates in view space. When moving by 'line' it uses model coordinates and can land inside a fold, causing VS Code to auto-unfold it. The new 'foldedLine' unit moves in model space but queries `viewModel.getHiddenAreas()` to detect folds and jump to the first visible line past each one, so folds are skipped without being opened. This is the semantics needed by vim's j/k motions (VSCodeVim/Vim#1004): each fold counts as exactly one step, matching how real vim treats folds. Fixes: VSCodeVim/Vim#1004
13f8179 to
a51c7f8
Compare
Replace the step-by-step simulation (O(count × folds)) with a single pass over sorted hidden areas (O(folds in path)). Compute a naive target, then extend it for each fold encountered, stopping before any fold that reaches the document boundary. Also extracts _targetFoldedDown/_targetFoldedUp helpers to eliminate the duplicated loop structure between the two directions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
alexdima
approved these changes
Feb 28, 2026
Member
alexdima
left a comment
There was a problem hiding this comment.
Hope you don't mind, I used my AI to fix your AI's small mistake
roblourens
approved these changes
Feb 28, 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.
Summary
Adds a new
foldedLinevalue to thebyparameter of thecursorMovecommand. When used withupordowndirections, the cursor moves by logical lines while treating each folded region as a single step — the entire fold is skipped rather than entered.Previously only
wrappedLine(view-space) andline(model-space) were available.wrappedLineskips folds as a side-effect of operating in view coordinates, but also splits long wrapped lines into multiple steps, which is incorrect for line-oriented movements.linemoves in model-space and enters folds.foldedLinemoves in model-space but queriesviewModel.getHiddenAreas()to detect and skip over folded regions.Behavior
select: true)up/downdirections; other directions ignore the unit and fall back to default behaviorTesting
New test suite:
Cursor move command - foldedLine unitincursorMoveCommand.test.tsRelated
Closes #81498