opencode icon indicating copy to clipboard operation
opencode copied to clipboard

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

Open edlsh opened this issue 3 weeks ago • 0 comments

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 avatar Dec 28 '25 04:12 edlsh