Skip to content

feat(trees): Keep file-tree search open and interactive#1022

Open
necolas wants to merge 3 commits into
mainfrom
apply-trees-patches
Open

feat(trees): Keep file-tree search open and interactive#1022
necolas wants to merge 3 commits into
mainfrom
apply-trees-patches

Conversation

@necolas

@necolas necolas commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Before, a file-tree search was a temporary mode. It closed as soon as the user clicked a row or pressed Enter, and the user could not change which directories the search expanded. Now the search stays open, and the user can work inside the results.

What the user can now do

  • Click a row and keep the search open. A click selects the row and leaves the search open. The user can select several results and refine the query.
  • Press Enter and keep the search open. Enter selects the focused match and leaves the search open. Focus stays in the search input, so the user can select more matches without a new search.
  • Collapse a directory in the results. During a hide-non-matches search, the user can collapse a matched directory to hide its matches. The search keeps that choice until the user clears the search.

How it works

Each commit is a self-contained change:

  1. Keep search open after a row click — the click plan returns closeSearch: false.
  2. Keep search open when the user presses Enter — the Enter handler selects the focused match and no longer closes the search. The inline rename path (F2) still closes the search and restores the scroll.
  3. Let the user collapse directories during search — the controller keeps a set of the directories the user collapsed. Each search refresh keeps them collapsed but still visible, filters the visible rows from that state, prunes stale directories, remaps them through tree mutations, and clears the set when the search closes. The controller now tracks matches outside the visibility pass, so match navigation still uses the full match set.

Source of the change

These commits port the @pierre/trees patch from the diffy project into the TypeScript source. The original patch changed the built dist/, so this PR applies the same behavior to src/. The upstream patch also carried an expand/reveal override, but @suveshmoza confirmed it is not needed, so this PR drops it and keeps only the reachable collapse behavior. This PR also updates the affected tests and adds a controller test for the collapse override.

Test plan

  • moon run root:format root:lint
  • moonx trees:typecheck
  • moonx trees:test
  • moonx trees:test-e2e

necolas added 2 commits July 23, 2026 14:24
Before, a click on a row closed an open file-tree search and returned
to the full tree. Now the click keeps the search open. The user can
then select results and refine the search.

A row click now always keeps the search open. The click plan returns
closeSearch: false. The field stays on the plan. It gives the close
decision one place to change later.
Before, Enter selected the focused match and closed an open file-tree
search. Now Enter selects the focused match and keeps the search open.
The user can then select several matches without a new search.

The Enter handler no longer records a viewport offset, sets the
restore-focus flag, or calls closeSearch. Focus stays in the search
input. The inline rename path (F2) still closes the search and
restores the scroll. This change also updates the affected tests.
@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jul 24, 2026 7:46pm
pierre-docs-diffshub Ready Ready Preview Jul 24, 2026 7:46pm
pierre-docs-trees Ready Ready Preview Jul 24, 2026 7:46pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pierrejs-diff-demo Skipped Skipped Jul 24, 2026 7:46pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6536e10b8b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/trees/src/model/FileTreeController.ts Outdated
@necolas
necolas requested review from SlexAxton and mdo July 23, 2026 21:40
@necolas

necolas commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

cc @suveshmoza

@necolas
necolas force-pushed the apply-trees-patches branch from 6536e10 to 2040197 Compare July 23, 2026 22:21
@vercel
vercel Bot temporarily deployed to Preview – pierrejs-diff-demo July 23, 2026 22:21 Inactive
@necolas

necolas commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Codex correctly flagged that the expand override is not reachable in hide-non-matches search. Example:

src/
  utils/
    worker.ts   (matches "worker")
    stream.ts   (no match)
  components/   (no match)

Searching worker shows only src/ › utils/ › worker.ts. Clicking utils/ (already open) can only collapse it, and stream.ts / components/ are not rendered, so there is no row to click that would expand a folder and reveal its non-matching files. The expand half of the override map — and the reveal loop in #syncSearchVisibilityState — is plumbed but has no trigger in this mode. The collapse direction works and is reachable.

I kept the code faithful to the diffy patch and reworded the PR and commit to describe only the reachable (collapse) behavior.

@suveshmoza was a trigger for the expand/reveal intended as a follow-up or could that path be dropped?

@suveshmoza

Copy link
Copy Markdown

It can be dropped

Before, a hide-non-matches search expanded only the matches and their
ancestors, and the user could not change that layout. Now the user can
collapse a matched directory during the search to hide its matches. The
search keeps that choice until the user clears the search.

The controller keeps a set of the directories the user collapsed. On
each search refresh it keeps those directories collapsed but still
visible, and filters the visible rows from that state. It also prunes
stale directories, remaps them through tree mutations, and clears the
set when the search closes. The controller now tracks matches outside
the visibility pass, so match navigation still uses the full match set.
@necolas
necolas force-pushed the apply-trees-patches branch from 2040197 to 0dc991a Compare July 24, 2026 19:45
@vercel
vercel Bot temporarily deployed to Preview – pierrejs-diff-demo July 24, 2026 19:45 Inactive
@necolas

necolas commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Dropped the expand/reveal path per @suveshmoza. The override is now a plain Set of collapsed directories (collapse-only): I removed the expand branch from toggleMountedDirectoryFromInput, the reveal loop in #syncSearchVisibilityState, and the expand handling in #refreshActiveSearchState, and simplified the map to a set. The reachable collapse behavior is unchanged.

Renamed the test to file-tree-search-manual-collapse.test.ts and reworded the PR and commit. Force-pushed; moonx trees:test (327) and moonx trees:test-e2e (58) pass.

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