feat: add zA (toggle fold recursively) - #10060
Open
edsattar wants to merge 2 commits into
Open
Conversation
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.
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.
What this PR does / why we need it:
In real Vim,
zAtoggles 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 implementsza(single-level toggle),zO(recursive open), andzC(recursive close) insrc/actions/commands/fold.ts, butzAwas never added, so pressing it currently does nothing.This adds a
zAaction. 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'svisibleRanges(the header line stays visible even when its body is collapsed).editor.unfoldRecursively, matchingzO.editor.foldwithdirection: "up"and an effectively unlimitedlevels, closing the fold at the cursor and climbing outward through every enclosing fold, matching the fix proposed forzCin fix: zC only closes the innermost fold, not enclosing ones #10062. (An earlier version of this PR used bareeditor.foldRecursivelyhere, which shares the same bug reported in zC (close all folds recursively) only closes the innermost fold, not enclosing folds #10061, only the innermost fold closes, not its ancestors. Updated to use the same corrected approach.)Which issue(s) this PR fixes
Fixes #10059
Special notes for your reviewer:
zCfix). If that PR's approach changes during review, this one should follow suit for consistency.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.doesActionApplymirrors the same operator-guard comment used byCommandFold(avoiding conflicts with the Sneak plugin's<operator>z).zAnow closes all three levels in one press (matchingzC's fixed result), and toggling again reopens all three (matchingzO).