Skip to content

Conversation

@edlsh
Copy link
Contributor

@edlsh edlsh commented Dec 28, 2025

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?

Aspect Inline (this PR) Modal (#5775)
UX Convention Matches bash/zsh/fish exactly IDE-style picker
Context Stays in prompt, see full content Separate overlay
State Management Reuses existing textarea/extmarks Needs separate rendering
Complexity Localized to one component Additional 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

@edlsh edlsh force-pushed the feat/inline-ctrl-r-history-search branch 2 times, most recently from fab03e0 to fb1736c Compare December 28, 2025 04:19
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 edlsh force-pushed the feat/inline-ctrl-r-history-search branch from fb1736c to 35f4348 Compare December 28, 2025 04:28
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: sst#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: sst#6276
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

1 participant