feat: prompt history recall + undo/redo#34
Open
saucam wants to merge 1 commit into
Open
Conversation
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>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
| } | ||
| } | ||
| self.history_index = None; | ||
| self.history_draft = None; |
There was a problem hiding this comment.
Minor opportunity to reduce allocation
In history_prev(), self.prompt_history[index].clone() creates a new String, then set_prompt_text() splits it back into lines. Since we have &String from the vector, we could pass a reference to avoid the intermediate clone. However, this is a micro-optimization and the current code is perfectly readable and correct.
Suggested fix:
Suggested change
| self.history_draft = None; | |
| Consider changing `set_prompt_text` to accept `&str` and pass `&self.prompt_history[index]` directly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Second of two PRs borrowing prompt-editor ideas from
earendil-works/pi-tui. Adds the everyday-friction fixes to the prompt editor.Prompt history (
↑/↓)Recall previously submitted prompts, shell-style.
↑recalls only when the cursor is on the first row,↓only on the last row — so multi-line cursor movement is untouched.↓past the newest entry restores the in-progress draft you had before browsing.PROMPT_HISTORY_MAX(200).@-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_promptnow records the submitted text and resets navigation.Action::{UndoPrompt, RedoPrompt, HistoryPrev, HistoryNext}.Testing
cargo test --workspacegreen (323 tui tests).cargo fmt --checkclean; new code clippy-pedantic clean.🤖 Generated with Claude Code