Skip to content

Conversation

@jiahaoxiang2000
Copy link

@jiahaoxiang2000 jiahaoxiang2000 commented Dec 19, 2025

Summary

Implements Ctrl+R history search functionality for the TUI prompt, allowing users to fuzzy search through their prompt history.

Image

Changes

  • Added DialogHistorySearch component with fuzzy filtering and deduplication
  • Increased max history entries from 50 to 100
  • Added items getter and reset() method to PromptHistory context
  • Added history_search keybind (default: ctrl+r) to config
  • Integrated history search into prompt component

Closes #5062
Related #6276

- Replace simple select dialog with advanced fuzzy search interface
- Add fuzzysort integration for intelligent text matching
- Implement keyboard navigation (arrows, page up/down, vi keys)
- Add real-time filtering with match highlighting preview
- Improve visual design with selection highlighting and theming
- Add mouse support for item selection and hover navigation
- Add Ctrl+U keyboard shortcut to clear search filter
edlsh added a commit to edlsh/opencode that referenced this pull request Dec 28, 2025
Implements bash-style inline history search as suggested in sst#5062.
Alternative approach to sst#5775's modal dialog.

Features:
- Inline reverse-i-search: preview matches directly in prompt textarea
- Incremental substring search with real-time updates
- Keyboard controls: Ctrl+R/Up cycle older, Down for newer, Enter accept, Esc/Ctrl+G cancel
- Status line showing (reverse-i-search)'query': N/M
- Full state preservation: prompt text, parts, extmarks, mode, cursor position
- Configurable keybind (history_search, default: ctrl+r)

Implementation details:
- historySearch state tracks: active, query, matchIndex, originalPrompt, originalMode, originalCursorOffset
- Exposed history.items getter for direct access to prompt history
- History search takes precedence over shell-mode and other handlers when active
- Paste blocked during search mode
- Preview updates parts/extmarks consistently with normal history navigation

Closes sst#5062
Related to sst#1701
@edlsh
Copy link
Contributor

edlsh commented Dec 28, 2025

Hey @jiahaoxiang2000! I implemented an alternative approach in #6276 that uses inline reverse-i-search (bash-style) instead of a modal dialog.

Key differences:

  • Matches display directly in the prompt textarea rather than a separate dialog
  • Follows the exact bash/zsh/fish convention: (reverse-i-search)'query': N/M
  • Reuses existing prompt rendering for parts/extmarks instead of creating a separate list view

This was inspired by @ShpetimA's suggestion in #5062:

Maybe just simple search style like bash where you search and it shows on the input instantly instead of opening history modal.

Both approaches have merit - the modal provides a visual list which some users might prefer, while inline keeps the shell-like feel. Curious what the maintainers think about which direction fits better for opencode's TUI!

edlsh added a commit to edlsh/opencode that referenced this pull request Dec 28, 2025
Implements bash-style inline history search as suggested in sst#5062.
Alternative approach to sst#5775's modal dialog.

Features:
- Inline reverse-i-search: preview matches directly in prompt textarea
- Incremental substring search with real-time updates
- Keyboard controls: Ctrl+R/Up cycle older, Down for newer, Enter accept, Esc/Ctrl+G cancel
- Status line showing (reverse-i-search)'query': N/M
- Full state preservation: prompt text, parts, extmarks, mode, cursor position
- Configurable keybind (history_search, default: ctrl+r)

Implementation details:
- historySearch state tracks: active, query, matchIndex, originalPrompt, originalMode, originalCursorOffset
- Exposed history.items getter for direct access to prompt history
- History search takes precedence over shell-mode and other handlers when active
- Paste blocked during search mode
- Preview updates parts/extmarks consistently with normal history navigation

Closes sst#5062
Related to sst#1701
edlsh added a commit to edlsh/opencode that referenced this pull request Dec 28, 2025
Implements bash-style inline history search as suggested in sst#5062.
Alternative approach to sst#5775's modal dialog.

Features:
- Inline reverse-i-search: preview matches directly in prompt textarea
- Incremental substring search with real-time updates
- Keyboard controls: Ctrl+R/Up cycle older, Down for newer, Enter accept, Esc/Ctrl+G cancel
- Status line showing (reverse-i-search)'query': N/M
- Full state preservation: prompt text, parts, extmarks, mode, cursor position
- Configurable keybind (history_search, default: ctrl+r)

Implementation details:
- historySearch state tracks: active, query, matchIndex, originalPrompt, originalMode, originalCursorOffset
- Exposed history.items getter for direct access to prompt history
- History search takes precedence over shell-mode and other handlers when active
- Paste blocked during search mode
- Preview updates parts/extmarks consistently with normal history navigation

Closes sst#5062
Related to sst#1701
edlsh added a commit to edlsh/opencode that referenced this pull request Dec 28, 2025
Implements bash-style inline history search as suggested in sst#5062.
Alternative approach to sst#5775's modal dialog.

Features:
- Inline reverse-i-search: preview matches directly in prompt textarea
- Incremental substring search with real-time updates
- Keyboard controls: Ctrl+R/Up cycle older, Down for newer, Enter accept, Esc/Ctrl+G cancel
- Status line showing (reverse-i-search)'query': N/M
- Full state preservation: prompt text, parts, extmarks, mode, cursor position
- Configurable keybind (history_search, default: ctrl+r)

Implementation details:
- historySearch state tracks: active, query, matchIndex, originalPrompt, originalMode, originalCursorOffset
- Exposed history.items getter for direct access to prompt history
- History search takes precedence over shell-mode and other handlers when active
- Paste blocked during search mode
- Preview updates parts/extmarks consistently with normal history navigation

Closes sst#5062
Related to sst#1701
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.

[FEATURE]: Ctrl+R to search and navigate prompt history instead of just arrow keys

2 participants