Skip to content

feat(tui): add inline Ctrl+R reverse-i-search for prompt history - #6276

Closed
edlsh wants to merge 3 commits into
anomalyco:devfrom
edlsh:feat/inline-ctrl-r-history-search
Closed

feat(tui): add inline Ctrl+R reverse-i-search for prompt history#6276
edlsh wants to merge 3 commits into
anomalyco:devfrom
edlsh:feat/inline-ctrl-r-history-search

Conversation

@edlsh

Copy link
Copy Markdown
Contributor

Summary

Implements bash-style inline reverse-i-search for prompt history, as an alternative approach to #5775's modal dialog. This addresses #5062 and #1701.

As @ShpetimA suggested in #5062:

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

Demo

The search works inline in the prompt textarea with a status line in the footer:

(reverse-i-search)'git co': 2/5 ctrl+r next esc cancel enter select

Features

  • Inline preview: Matches display directly in the prompt textarea (no modal)
  • Incremental search: Real-time substring matching as you type
  • Full keyboard controls:
    • Ctrl+R / Up: Cycle to older matches
    • Down: Cycle to newer matches
    • Enter: Accept current match
    • Esc / Ctrl+G: Cancel and restore original prompt
  • Complete state preservation: Prompt text, file/agent parts, extmarks, mode, and cursor position
  • Configurable keybind: history_search (default: ctrl+r)

Implementation Details

  • Added historySearch state to Prompt store tracking: active, query, matchIndex, originalPrompt, originalMode, originalCursorOffset
  • Exposed history.items getter for direct access to prompt history
  • History search handler takes precedence over shell-mode and other key handlers when active
  • Preview updates parts/extmarks consistently with normal history navigation
  • Paste blocked during search mode
  • Supports space character in search queries (e.name === "space" handling)

Why Inline vs Modal?

AspectInline (this PR)Modal (#5775)
UX ConventionMatches bash/zsh/fish exactlyIDE-style picker
ContextStays in prompt, see full contentSeparate overlay
State ManagementReuses existing textarea/extmarksNeeds separate rendering
ComplexityLocalized to one componentAdditional dialog component

For a terminal TUI that already uses shell-like behaviors, inline Ctrl+R is the more cohesive choice.

Closes#5062
Related to #1701, #5775

Implements bash-style inline history search as suggested in #5062.
Alternative approach to #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#5062
Related to #1701
After accepting a history search match, set the history navigation
index so Up/Down continues from that position instead of resetting.
Adds setIndex method to PromptHistory context.
Ref: #6276
Escape was being intercepted by session_interrupt (bound to escape)
before reaching history search handler. Suspend command keybinds
while history search is active so Escape/Ctrl+G properly cancel.
Ref: #6276
Sign up for freeto 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

1 participant

@edlsh