Skip to content

feat(filepicker): add search/filter functionality#994

Open
toller892 wants to merge 1 commit into
charmbracelet:mainfrom
toller892:feat/filepicker-search
Open

feat(filepicker): add search/filter functionality#994
toller892 wants to merge 1 commit into
charmbracelet:mainfrom
toller892:feat/filepicker-search

Conversation

@toller892
Copy link
Copy Markdown

Summary

Adds incremental search to the file picker component, allowing users to filter visible files by name within the current directory.

Motivation

Finding a specific file in a large directory is tedious — you have to scroll through everything. This adds vim-style / search to filter files in place. (bubbletea#1685)

Usage

Key Action
/ Enter search mode
Type Filter files (case-insensitive substring match)
Enter Confirm filter, return to browsing
Esc (in search) Exit search mode; if filter was applied, clear it
Esc (browsing) Clear active filter; if no filter, navigate to parent dir

All navigation keys (j/k/g/G/PgUp/PgDn) work on the filtered list. Entering a directory clears the search.

Implementation

  • FilterFunc type + DefaultFilter (case-insensitive substring) for customizable filtering
  • Filter field on Model — users can swap in fuzzy matching (sahilm/fuzzy) or any custom logic
  • Search uses textinput.Model (same pattern as list component's filter)
  • filteredFiles / filteredMap track the mapping between filtered and original indices
  • Navigating into a directory or pressing Back clears the search automatically

Testing

go build ./filepicker/
go vet ./filepicker/
go test ./...

All pass. The filepicker has no existing test file; I can add tests if desired.

Add incremental search to the file picker component, allowing users to
filter visible files by name. Press '/' to enter search mode, type to
filter, Enter to confirm, Esc to cancel.

Changes:
- Add '/' key binding to enter search mode with a text input
- Filter displayed files using case-insensitive substring matching
- Show search bar while typing, filter status bar when confirmed
- Navigation keys (j/k/g/G/pgup/pgdown) work on filtered list
- Esc clears filter first, then navigates to parent directory
- Entering a directory clears the active search
- Add FilterFunc type and DefaultFilter for customizable filtering
- Add Filter field to Model for user-supplied filter functions

Fixes charmbracelet/bubbletea#1685
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.

1 participant