Skip to content

feat: add zA (toggle fold recursively) - #10060

Open
edsattar wants to merge 2 commits into
VSCodeVim:masterfrom
edsattar:feat/toggle-fold-recursively
Open

feat: add zA (toggle fold recursively)#10060
edsattar wants to merge 2 commits into
VSCodeVim:masterfrom
edsattar:feat/toggle-fold-recursively

Conversation

@edsattar

@edsattar edsattar commented Jul 14, 2026

Copy link
Copy Markdown

What this PR does / why we need it:

In real Vim, zA toggles the fold under the cursor recursively: it closes an open fold (and everything nested inside it), or opens a closed fold (and everything nested inside it), depending on the fold's current state. VSCodeVim already implements za (single-level toggle), zO (recursive open), and zC (recursive close) in src/actions/commands/fold.ts, but zA was never added, so pressing it currently does nothing.

This adds a zA action. Since VS Code has no built-in "toggle fold recursively" command, the action determines current state itself: a fold is closed if the line immediately after its header is absent from the editor's visibleRanges (the header line stays visible even when its body is collapsed).

Which issue(s) this PR fixes

Fixes #10059

Special notes for your reviewer:

  • This PR's close-direction logic now depends on the same reasoning as fix: zC only closes the innermost fold, not enclosing ones #10062 (zC fix). If that PR's approach changes during review, this one should follow suit for consistency.
  • No existing tests cover fold.ts (these commands dispatch to VS Code's live folding engine, which isn't simulated in the test harness), so I followed that existing convention rather than adding tests that wouldn't fit the pattern used by sibling fold commands.
  • doesActionApply mirrors the same operator-guard comment used by CommandFold (avoiding conflicts with the Sneak plugin's <operator>z).
  • Manually verified in a built Extension Development Host with a 3-level nested JS file: cursor on the deepest line, zA now closes all three levels in one press (matching zC's fixed result), and toggling again reopens all three (matching zO).

edsattar added 2 commits July 14, 2026 16:53
za, zO, and zC all work, but zA (toggle fold recursively) was never
implemented, so it silently does nothing. This adds it by checking
whether the line after the fold header is present in the editor's
visibleRanges to determine open/closed state, then dispatching
editor.unfoldRecursively or editor.foldRecursively accordingly.

Fixes VSCodeVim#10059
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.

zA (toggle fold recursively) does not work

1 participant