Skip to content

Search files by name in the editor's file tree - #215

Open
simo787c wants to merge 16 commits into
mainfrom
feat/search-files-in-editor-4b7
Open

simo787c wants to merge 16 commits into
mainfrom
feat/search-files-in-editor-4b7

Conversation

@simo787c

@simo787c simo787c commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a search box above the editor's file tree. While a query is active, the tree is hidden and a flat ranked list takes its place: the file name in the tree's mono font, the folder dimmed, matched letters highlighted, the full path on hover, a count line (146 files, or 200 of 500 files when the list is cut), a clear button and a "No files match" / "Loading…" state.
  • Built on the shared ui/Command (cmdk) with shouldFilter={false}. The file list comes from the tree, so search follows the "changed only" toggle and "show all files" mode. Ignored directories match as their single collapsed entry.
  • Fuzzy subsequence matching (edsb finds EditorSidebar.tsx). Ranking prefers file-name matches over directory-only ones, word starts and camelCase humps, and a clean word-start run over a scattered match; highlights follow the best of a few tried alignments. Pure logic in src/renderer/lib/fileSearch.ts with behaviour tests (order only, no score values); each ranking rule has a test that goes red when the rule is removed.
  • Keyboard: Up/Down/Enter in the box; Home/End move the caret; the first Esc clears the query and the second closes the editor. Modal gets one general data-owns-escape marker (the comment inputs use it too, replacing data-diff-comment-input); the search root sets it only while it has a query. No global key listeners, and the tree sits outside the cmdk root so its keys are untouched.
  • The tree stays mounted while searching, so your open folders and scroll position survive. A file picked from the results is revealed (its folders open, row scrolled into view) when the search is cleared.
  • Focus stays in the search box on any click inside it; IME composition is respected.
  • Version bumped to 0.24.0.

Not included

  • No global focus shortcut (not yet checked against Monaco/Dash keybindings).
  • No content (grep) search.

Known limits

  • Ranking runs synchronously per keystroke: about 50 ms at 50,000 paths, about 450 ms at 200,000 (this repo has about 650 files). Deferring it was tried and reverted because it left cmdk's highlight on stale rows.
  • cmdk's own Ctrl+N/J/K/P and Cmd+Up/Down bindings are active in the box, as in the branch picker.
  • A plain σ doesn't match a path-ending Σ.

Test plan

  • fileSearch unit tests (25), tsc, eslint
  • Reviewed by eleven rounds of blind, independent review; the last two found nothing that holds
  • Checked by hand in a second Dash instance: result look, open-file marker, truncation, hover path, Esc clear, no focus ring on clicks
  • Not yet checked by hand: the tree staying through a search (folders and scroll restored) and revealing the picked file; scrollbar drag in the results list with the new mouse-down guard
  • src/renderer/utils/__tests__/billionToast.test.ts fails on a locale format (1,278 vs 1.278); this PR doesn't touch it

🤖 Generated with Claude Code

Search box above the tree with ranked flat results, match highlighting and
keyboard navigation scoped to the input.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
@simo787c
simo787c marked this pull request as ready for review October 30, 2026 13:52
Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>

@nthomsencph nthomsencph left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Esc needs fixing before merge.

@simo787c
simo787c force-pushed the feat/search-files-in-editor-4b7 branch from a249b3a to d6821c5 Compare November 10, 2026 14:54
@simo787c

Copy link
Copy Markdown
Collaborator Author

Extras added beyond the review:

  • A count line under the search box ("146 files").
  • The full path shows when you hover a result.
  • The tree keeps its open folders and scroll position during a search.
  • The file you pick from the results is opened and scrolled to in the tree.
  • Clicking inside the search box keeps typing focus in it.
  • Home and End move the cursor in the search box.
  • Esc while typing with an IME no longer clears the search.
  • Ranking prefers a clean word match over a scattered one.
  • "Loading…" shows while the file list loads.
  • Screen readers hear the result count.

simo787c and others added 14 commits November 10, 2026 16:26
The file search now reads its files from the tree, uses the shared Command
list, and lets the first Esc clear the box instead of closing the editor.

- Esc closed the editor: a shared data-owns-escape marker, first Esc clears
- The file list was built twice: search takes its files from the tree
- Hand-written keys: results use ui/Command, the tree stays outside it
- Ranking tests could not fail: each rule has an order test that goes red
- Open file's row: the tree's background, normal-coloured mono name
- Long names: the name and the folder both truncate, the folder first

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
A small count line under the search box says how many files matched, and how
many of them are listed when the list is capped.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
Hovering a search result now shows its full path, as the tree rows already do,
so a truncated folder can still be read.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
Until the file list arrives the search only knows the changed files, so it
now shows Loading instead of a partial list, using the same rule as the tree.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
The count line now lives in a status region that is always there, so screen
readers announce the count, or that no files match, as the query changes.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
A click anywhere in the search area, including the Clear button, now leaves
focus in the box, so Esc and the arrow keys keep working and Enter never lands
on the button.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
The Command list used Home and End to jump to the first and last result, so
they never moved the caret; in the box they now move the caret again.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
When Esc only cancels an input method's composition, the search keeps its
query instead of clearing it.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
Search used to score and highlight only the first letters that fit, so a
clean word later in the name was ignored; it now tries a few word-start
alignments and keeps the best, and breaks ties with a plain, faster comparison.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
A query typed out as one unbroken run that starts a word, like `store` in
uiStore.ts, now ranks above letters picked from several words, even when those
start at the file name.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
A few characters, like `İ`, grow when lowercased, which shifted the
highlighted letters and could miss a query that contains one; paths and the
query are now lowercased so every character keeps its place.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
The tree now stays mounted, just hidden, while searching, so the folders you
opened and the scroll position are still there when the search ends.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
When the search is cleared after picking a file, the tree opens that file's
folders and scrolls its row into view, so you can see where it lives.

Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
Co-Authored-By: Claude <noreply@anthropic.com> via Dash <dash@syv.ai>
@simo787c
simo787c force-pushed the feat/search-files-in-editor-4b7 branch from d6821c5 to bf0355e Compare November 10, 2026 15:45
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