Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: zC only closes the innermost fold, not enclosing ones - #10062

Open
edsattar wants to merge 1 commit into
VSCodeVim:masterfrom
edsattar:fix/zC-close-recursively-ancestors
Open

fix: zC only closes the innermost fold, not enclosing ones#10062
edsattar wants to merge 1 commit into
VSCodeVim:masterfrom
edsattar:fix/zC-close-recursively-ancestors

Conversation

@edsattar

Copy link
Copy Markdown

What this PR does / why we need it:

zC is meant to close the fold under the cursor and every fold enclosing it, all the way out to the outermost level. Instead it only closes the single innermost fold directly containing the cursor, folds enclosing it stay open. This is because zC dispatches VS Code's native editor.foldRecursively, which recurses into descendants of the fold at the cursor, not ancestors.

zc (lowercase) already avoids this problem by using editor.fold with direction: "up" and a count-based levels argument, which correctly climbs outward through enclosing folds. This PR applies the same mechanism to zC, with an effectively unlimited level count instead of a count prefix, since zC (unlike zc) isn't meant to take a count, it always means "all levels."

Which issue(s) this PR fixes

Fixes #10061

Special notes for your reviewer:

  • This only touches zC. zO doesn't have the equivalent problem: closing a fold already hides everything nested inside it regardless of descendants' own state, so "recursing into descendants" is meaningless for close, but opening genuinely needs to cascade into nested closed folds, which editor.unfoldRecursively already does correctly.
  • Manually verified in a built Extension Development Host with a 3-level nested JS file: cursor on the deepest line, zC now collapses all three levels in one press, matching the fixed result exactly.
  • levels: 999 is a pragmatic "effectively unlimited" sentinel, VS Code's editor.fold naturally clamps to however many enclosing levels actually exist, verified directly rather than assumed.

zC dispatches editor.foldRecursively, which closes the single fold
directly containing the cursor (plus any of its own descendants), but
never climbs through the folds enclosing it. Vim's zC is supposed to
close every fold level containing the cursor, from innermost out to
the outermost. zc already handles this correctly via editor.fold with
direction 'up' and a count-based levels arg; this applies the same
mechanism to zC with an effectively unlimited level count instead of
relying on foldRecursively.
edsattar added a commit to edsattar/Vim that referenced this pull request Jul 14, 2026
Same root cause as the zC bug in VSCodeVim#10061: the close branch dispatched
editor.foldRecursively, which only closes the fold directly containing
the cursor and does not climb through enclosing folds. Switched to the
same editor.fold with direction 'up' and an unlimited levels approach
used to fix zC in VSCodeVim#10062, so zA's close direction now climbs all
enclosing folds from the cursor's position, not just the innermost one.
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.

zC (close all folds recursively) only closes the innermost fold, not enclosing folds

1 participant