Skip to content

fix: keep the folders a reader closed in a file tree when its paths change - #5937

Merged
max-sixty merged 1 commit into
mainfrom
nightly/file-tree-keeps-closed-folders
Nov 14, 2026
Merged

max-sixty merged 1 commit into
mainfrom
nightly/file-tree-keeps-closed-folders

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

When an lf-file-tree's paths change, a folder the reader closed now stays closed. Before this, it reopened at every update to the file list. The model listener also stops reading every visible row, which it did on each arrow key and each letter typed in search.

Cause. The widget builds its Trees model with initialExpansion: "open". resetPaths builds a new store from that option, which opens every folder whatever initialExpandedPaths lists. I checked this against the vendored @pierre/trees 1.0.0-beta.6 by calling FileTreeController.resetPaths with an empty list, then with one folder: both times every folder came back open. So the expansion list the widget kept, and handed to resetPaths, never changed the result.

The widget kept that list current in a tree.subscribe listener. It called getVisibleRows(0, getVisibleCount() - 1), which builds a row object for every visible row. Trees fires that listener on every focus move, search keystroke and selection, so the cost of each input grew with the tree. Root AGENTS.md's Responsiveness rules that out.

Change. The listener now only repaints the empty state and refreshes commands. At a path change, the widget reads which folders are closed from the old model and closes them again after resetPaths. Every other folder opens as before, new ones included. The module header now states what an update keeps.

Verification.

  • New test test_file_tree_keeps_the_folders_the_reader_closed_when_its_paths_change: it fails on main (src reads aria-expanded="true" after the update) and passes here.
  • The file's other file-tree tests pass: 6 passed with -k "file_tree".
  • pnpm run check:browser passes.

Found by the nightly survey of packages/file-tree/widgets/lf-file-tree.js.

…hange

lf-file-tree builds its Trees model with `initialExpansion: "open"`, and
`resetPaths` builds a fresh store from that option, which opens every folder
whatever `initialExpandedPaths` lists. So the list the widget passed there never
changed the result: a folder the reader closed reopened at the next update to
the file list.

The widget kept that list current by reading every visible row on each model
emit, which Trees fires on every arrow key and every letter typed in search, so
each of those inputs cost a pass over the expanded tree.

Now the model listener reads no rows. At a path change the widget reads which
folders are closed from the old model and closes them again in the new one;
every other folder, a new one included, opens as before.

Behavior changed: a folder the reader closed stays closed across a change to
the tree's paths (test_file_tree_keeps_the_folders_the_reader_closed_when_its_paths_change).
@max-sixty
max-sixty merged commit b647f2d into main Nov 14, 2026
6 checks passed
@max-sixty
max-sixty deleted the nightly/file-tree-keeps-closed-folders branch November 14, 2026 07:03
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.

2 participants