Skip to content

feat: prompt history recall + undo/redo - #34

Merged
saucam merged 3 commits into
feat/syntax-highlight-and-fuzzy-autocompletefrom
feat/prompt-undo-and-history
Jul 26, 2026
Merged

feat: prompt history recall + undo/redo#34
saucam merged 3 commits into
feat/syntax-highlight-and-fuzzy-autocompletefrom
feat/prompt-undo-and-history

Conversation

@saucam

@saucam saucam commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

What

Second of two PRs borrowing prompt-editor ideas from earendil-works/pi-tui. Adds the everyday-friction fixes to the prompt editor.

Stacked on #33 — base is feat/syntax-highlight-and-fuzzy-autocomplete, so this diff shows only the history/undo changes. Retarget to main once #33 merges.

Prompt history ( / )

Recall previously submitted prompts, shell-style.

  • Gated to the editor's vertical edges recalls only when the cursor is on the first row, only on the last row — so multi-line cursor movement is untouched.
  • Stepping past the newest entry restores the in-progress draft you had before browsing.
  • History is de-duplicated against the newest entry and capped at PROMPT_HISTORY_MAX (200).
  • Wired as a runtime-conditional binding in the reducer (same pattern as the existing esc-interrupt and @-mention Tab), since the decision depends on cursor row + history state that the static keymap can't see.

Undo / redo (Ctrl+Z / Ctrl+Y)

Mapped to tui-textarea's built-in edit history via explicit keymap actions — discoverable in the help modal + testable, rather than relying on the library's implicit default shortcuts.

Implementation

  • AppState: prompt_history / history_index / history_draft + record_history, set_prompt_text, history_prev, history_next.
  • take_prompt now records the submitted text and resets navigation.
  • New Action::{UndoPrompt, RedoPrompt, HistoryPrev, HistoryNext}.

Testing

  • cargo test --workspace green (323 tui tests).
  • New unit tests: history walk / draft-restore / dedup / cap, and the new keymap bindings.
  • cargo fmt --check clean; new code clippy-pedantic clean.

🤖 Generated with Claude Code

Second of two PRs borrowing prompt-editor ideas from pi-tui.

- Prompt history: Up/Down recall previously submitted prompts, shell-style.
  Recall is gated to the editor's vertical edges (Up on the first row, Down on
  the last) so multi-line cursor movement is untouched; it's wired as a
  runtime-conditional binding in the reducer (like the existing esc-interrupt
  and @-mention Tab) since it depends on cursor row + history state. Stepping
  down past the newest entry restores the stashed live draft. History is
  de-duplicated against the newest entry and capped at PROMPT_HISTORY_MAX.

- Undo/redo: Ctrl+Z / Ctrl+Y map to tui-textarea's built-in edit history via
  explicit keymap actions (discoverable + testable rather than relying on the
  library's default shortcuts).

State gains prompt_history / history_index / history_draft plus record_history,
set_prompt_text, history_prev, history_next. Full suite green; new unit tests
cover history walk/restore/dedup/cap and the new keymap bindings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@highflame-oracle highflame-oracle Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔮 Oracle Review

🎯 Start Here

crates/codeoid-tui/src/app.rs (~15 min) — Logic changes in app.rs


📋 PR Summary

What this PR does: feat: prompt history recall + undo/redo


🔍 Code Review

Review completed.

Review Stats: suggestion:1


Generated by Oracle - Highflame's AI Code Reviewer

Comment thread crates/codeoid-tui/src/state/mod.rs
history_prev/next cloned prompt_history[i] into a String only to satisfy the
borrow checker (can't hold &self.prompt_history[i] across a &mut self method).
Replace the set_prompt_text method with a free `prompt_from_text(&str)` that
doesn't borrow self, so callers pass &self.prompt_history[i] directly — no
intermediate allocation. Behaviour unchanged; history tests still green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@highflame-oracle highflame-oracle Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔮 Oracle Review

🎯 Start Here

crates/codeoid-tui/src/state/mod.rs (~21 min) — Security changes in mod.rs


📋 PR Summary

What this PR does: feat: prompt history recall + undo/redo


🔍 Code Review

Review completed.

Review Stats: suggestion:1


Generated by Oracle - Highflame's AI Code Reviewer

Comment thread crates/codeoid-tui/src/state/mod.rs
Front-trimming a Vec on each cap is an O(n) shift; a VecDeque makes dropping
the oldest entry an O(1) pop_front, which is the semantically correct
structure for a bounded ring buffer with front removals. Negligible at the
200-entry cap, but cleaner and future-proof. Behaviour and tests unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saucam
saucam merged commit a9d9647 into feat/syntax-highlight-and-fuzzy-autocomplete Jul 26, 2026
2 checks passed
saucam added a commit that referenced this pull request Jul 26, 2026
…lete (#33)

* feat: syntax-highlighted code blocks + fuzzy / @-file prompt autocomplete

Borrows three ideas from earendil-works/pi-tui, adapted to our Ratatui stack:

- Syntax highlighting: fenced code in assistant markdown is highlighted by
  language via syntect (pure-Rust fancy-regex, no C toolchain). Common LLM
  fence tags are normalised to a known syntax; unknown languages fall back to
  the previous flat-green rendering. Highlighting is stateful across a block
  and paid once per message version through the existing render cache.

- @-file mention autocomplete: typing @ in the prompt opens a filesystem
  palette (relative to the focused session workdir), fuzzy-ranked against the
  partial path. Tab completes the top hit — directories keep a trailing slash
  to drill in, files get a trailing space. Handled as a runtime-conditional
  Tab binding, mirroring the existing esc-interrupts pattern.

- Fuzzy slash-command matching: the / palette and Tab completion now rank by
  a fuzzy subsequence score (consecutive-run + word-boundary bonuses, gap
  penalties) instead of strict prefix; Tab commits the best match.

New modules: fuzzy (scoring), mention (fs suggestions), render/highlight
(syntect wrapper). All new code is clippy-pedantic clean, with unit tests
across every new module.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* feat: prompt history recall + undo/redo (#34)

* feat: prompt history recall + undo/redo

Second of two PRs borrowing prompt-editor ideas from pi-tui.

- Prompt history: Up/Down recall previously submitted prompts, shell-style.
  Recall is gated to the editor's vertical edges (Up on the first row, Down on
  the last) so multi-line cursor movement is untouched; it's wired as a
  runtime-conditional binding in the reducer (like the existing esc-interrupt
  and @-mention Tab) since it depends on cursor row + history state. Stepping
  down past the newest entry restores the stashed live draft. History is
  de-duplicated against the newest entry and capped at PROMPT_HISTORY_MAX.

- Undo/redo: Ctrl+Z / Ctrl+Y map to tui-textarea's built-in edit history via
  explicit keymap actions (discoverable + testable rather than relying on the
  library's default shortcuts).

State gains prompt_history / history_index / history_draft plus record_history,
set_prompt_text, history_prev, history_next. Full suite green; new unit tests
cover history walk/restore/dedup/cap and the new keymap bindings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix: drop redundant clone in prompt history recall (oracle review)

history_prev/next cloned prompt_history[i] into a String only to satisfy the
borrow checker (can't hold &self.prompt_history[i] across a &mut self method).
Replace the set_prompt_text method with a free `prompt_from_text(&str)` that
doesn't borrow self, so callers pass &self.prompt_history[i] directly — no
intermediate allocation. Behaviour unchanged; history tests still green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* refactor: back prompt history with VecDeque (oracle review)

Front-trimming a Vec on each cap is an O(n) shift; a VecDeque makes dropping
the oldest entry an O(1) pop_front, which is the semantically correct
structure for a bounded ring buffer with front removals. Negligible at the
200-entry cap, but cleaner and future-proof. Behaviour and tests unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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