Skip to content

Feat(tree): add the ability to fold and unfold (recursively) tree nodes.#293

Merged
esmuellert merged 10 commits intoesmuellert:mainfrom
NeOzay:main
Mar 5, 2026
Merged

Feat(tree): add the ability to fold and unfold (recursively) tree nodes.#293
esmuellert merged 10 commits intoesmuellert:mainfrom
NeOzay:main

Conversation

@NeOzay
Copy link
Contributor

@NeOzay NeOzay commented Mar 1, 2026

This pull request adds Vim-style fold keymaps for tree views in both the explorer and history panels, making it easier to expand and collapse directory and group nodes. It introduces a reusable utility for fold operations, updates configuration and help documentation, and extends the tree node API to support recursive folding.

Fold keymap support and tree utilities

  • Added a new utility module lua/codediff/ui/lib/tree_utils.lua that provides functions to set up fold keymaps (zo, zO, zc, zC, za, zA, zR, zM) and helpers to find foldable nodes and operate on tree roots. This module is now used in both explorer and history keymap setup.
  • Updated the explorer and history keymap setup (lua/codediff/ui/explorer/keymaps.lua, lua/codediff/ui/history/keymaps.lua) to call tree_utils.setup_fold_keymaps, enabling fold operations in both panels. [1] [2] [3] [4]

Tree node API enhancements

  • Extended the tree node API (lua/codediff/ui/lib/tree.lua) with new methods: is_foldable, expand_recursively, and collapse_recursively, allowing recursive expand/collapse for group and directory nodes. [1] [2]

Configuration and documentation updates

  • Added fold keymaps to the plugin configuration (lua/codediff/config.lua) under both explorer and history keymap tables, making them customizable.
  • Updated the keymap help window (lua/codediff/ui/keymap_help.lua) to display descriptions for all new fold keymaps in explorer and history panels. [1] [2]

Fix: #278

(automatically generated by Github)

Deduplicate fold actions (open/close/toggle + recursive + all variants),
update_tree_view, fold_bindings table, and keymap registration loop that
were nearly identical in explorer/actions.lua and history/keymaps.lua.

Also adds fold keymaps to config defaults, keymap help, and Node methods
(is_foldable, expand/collapse_recursively) to the tree library.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 1, 2026 16:51
@NeOzay NeOzay marked this pull request as draft March 1, 2026 16:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Vim-style fold/unfold keymaps to the explorer and history tree views, backed by a reusable fold utility and small tree node API extensions to support recursive expand/collapse.

Changes:

  • Introduce tree-utils helper to set up fold keymaps (zo, zO, zc, zC, za, zA, zR, zM) for tree buffers.
  • Extend tree node API with is_foldable, expand_recursively, and collapse_recursively.
  • Expose fold keymaps in config defaults and display them in the keymap help UI.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
lua/codediff/ui/lib/tree.lua Adds foldability detection and recursive expand/collapse methods on tree nodes.
lua/codediff/ui/lib/tree-utils.lua New shared utility to find foldable nodes and register fold keymaps for tree panels.
lua/codediff/ui/explorer/keymaps.lua Wires fold keymap setup into explorer panel keymaps.
lua/codediff/ui/history/keymaps.lua Wires fold keymap setup into history panel keymaps.
lua/codediff/config.lua Adds configurable fold key defaults for explorer and history.
lua/codediff/ui/keymap_help.lua Displays the new fold keymaps in the help window.
CLAUDE.md Adds repo guidance for Claude Code usage and common dev commands.

@NeOzay
Copy link
Contributor Author

NeOzay commented Mar 1, 2026

@esmuellert
Hello, is my PR written correctly?

I also need to remove Claude.md

NeOzay and others added 5 commits March 3, 2026 17:56
- Rename tree-utils.lua to tree_utils.lua (snake_case convention)
- Update all require() calls in explorer and history keymaps
- Add nil guards in find_foldable_node() and get_root_node()
- Retrieve winid dynamically via vim.fn.bufwinid() instead of passing it
- Fix set_expanded_recursively() logic (was skipping foldable nodes)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CLAUDE.md is a local-only file for Claude Code guidance.
Remove it from git tracking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover is_foldable() for all node types (group, directory, commit,
title, file, and untyped). Cover expand_recursively() and
collapse_recursively() propagation rules, including the history
scenario where commit nodes are non-foldable. Cover interaction
with render() to verify buffer output reflects fold state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document fold keymaps (zo/zO/zc/zC/za/zA/zR/zM) for explorer
and history panels, history refresh keymap (R), and conflict
accept-all shortcuts (cT/cO/cB/cX).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a warning notification with source location when a
fold binding key is missing from the keymaps config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NeOzay NeOzay marked this pull request as ready for review March 3, 2026 17:46
@NeOzay NeOzay requested a review from Copilot March 3, 2026 17:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

NeOzay and others added 3 commits March 3, 2026 20:47
Extract keymaps[binding.key] into a local variable and
check for nil specifically, so that false can be used to
intentionally disable a fold keymap without triggering a
warning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove vim.notify warning when a fold keymap is nil/disabled.
This matches the existing codebase convention where missing keymaps
are silently skipped (e.g. explorer/history keymap setup).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add fold keymap entries (zo/zO/zc/zC/za/zA/zR/zM) to explorer and
history sections in codediff.txt vimdoc.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@esmuellert esmuellert enabled auto-merge March 5, 2026 02:41
@esmuellert esmuellert merged commit 2d291b0 into esmuellert:main Mar 5, 2026
13 checks passed
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.

[Feature Request]: recursively fold and unfold the explorer tree nodes.

3 participants