Skip to main content

Module file_tree

Module file_tree 

Source
Expand description

File-tree buffer (DESIGN.md §5.9 buffer-as-content).

v1 status (B.1.d): a flattened, lazily-expanded tree rendered one entry per line. <CR> on a directory toggles its expansion; on a file opens that file as a new Document buffer through the standard :e FILE path. Standard motions (j/k/0/$/G/gg/<C-d>/…) navigate via the active-buffer routing in lattice_core::ui::pane – the file tree carries no special motion bindings of its own.

The buffer is read-only (mutations error with the same “read-only” echo as the help buffer). The rendered text is a [lattice_core::Buffer] derived from the entry list; the same buffer feeds syntax highlighting and motions that need the line text.

§Where does “the root”, “the entry list”, “nerd-fonts” live?

Not on FileTreeBuffer. M.3.2.c.5 retired the struct fields; the canonical answer for each is a BufferLocal owned by file-tree-mode:

The FileTreeBuffer carries only the rendered rope + cursor + scroll. Operations that need the entry list / root / nerd-fonts flag take them as explicit parameters or read them from buffer-locals through the App’s chokepoint helpers. Mutations to the entry list flow through toggle_entries_at (a pure function that takes &mut Vec<FileTreeEntry>), so the App can orchestrate “update locals + re-render rope” as one atomic step and no struct mirror exists to drift.

Re-exports§

pub use modes::FileTreeEntries;
pub use modes::FileTreeMode;
pub use modes::FileTreeNerdFonts;
pub use modes::FileTreeRoot;
pub use modes::register_file_tree_modes;

Modules§

modes
file-tree-mode – major mode for the file-tree buffer + its BufferLocal-owned per-buffer state (root, entries, nerd-fonts toggle).

Structs§

FileTreeBuffer
One open file-tree buffer. Carries only the rendered rope and motion state (cursor + scroll). All “where does this buffer point” data – root, entry list, nerd-fonts toggle – lives in the App’s BufferLocals map under the modes::FileTreeRoot / modes::FileTreeEntries / modes::FileTreeNerdFonts keys.
FileTreeEntry
One row in the rendered file tree. depth controls the indentation prefix; kind decides whether <CR> toggles expansion or opens a file.

Enums§

FileTreeEntryKind

Functions§

entry_at_line
Look up the entry at line in an entry list. The App reads FileTreeEntries from buffer-locals and calls this with app.cursor.line for <CR> dispatch.
initial_entries
Build the initial entry list for root: the root itself as a depth-0 expanded directory, plus its immediate children at depth 1.
listing_entries
Project the tree’s entries into the shape directory-listing-mode reads (DL.2’s shared local).
render_to_buffer
Serialise the entry list to a [Buffer]. Each row is <indent><marker><icon><name> where <marker> is ▾ for an expanded dir, ▸ for a collapsed dir, and for a file. Indent is two spaces per depth. The <icon> glyph comes from lattice_core::ui::icons::glyph_for_entry – nerd-fonts when nerd_fonts is true, the BMP-block fallback palette otherwise. Both palettes occupy two cells, so column geometry is the same either way.
render_to_text
The tree’s rope text: indent, expand marker, name — and no icon.
toggle_entries_at
Toggle expansion of the directory entry at index (1-based within entries). Children of newly-expanded directories are inserted right after the directory’s row at depth + 1; closing a directory removes every entry whose depth is strictly greater than the closing one until depth drops back. No-op for non-directory rows.