feat(ui): shell-style message history recall in the chat composer#2284
Open
Feelings0220 wants to merge 1 commit into
Open
feat(ui): shell-style message history recall in the chat composer#2284Feelings0220 wants to merge 1 commit into
Feelings0220 wants to merge 1 commit into
Conversation
ArrowUp on the composer's first line steps back through this session's previously sent messages (consecutive duplicates collapsed); ArrowDown steps forward and finally restores the unsent draft. Guards keep normal editing intact: recall only fires with a collapsed cursor on the first/last line, never during IME composition, and any manual edit or send exits history-browsing mode. The cursor lands at the end of each recalled message. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016d9SxeefoRSLZmQ1oKo17j
Contributor
There was a problem hiding this comment.
Pull request overview
Adds shell-style message history navigation to the chat composer in the UI so users can recall previously sent messages from the current session with ArrowUp/ArrowDown while preserving normal multiline editing and IME behavior.
Changes:
- Computes a session-scoped history of user message texts (collapsing consecutive duplicates) for recall.
- Adds ArrowUp/ArrowDown key handling with guards (first/last line + collapsed cursor + not composing) and restores the unsent draft when stepping past the newest entry.
- Tracks history navigation state via refs (current history index + draft buffer) and exits history mode on send and manual edits.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+116
to
+117
| // Shell-style composer history: this session's user message texts, oldest | ||
| // first, consecutive duplicates collapsed. Recalled with ArrowUp/ArrowDown. |
Comment on lines
+116
to
+130
| // Shell-style composer history: this session's user message texts, oldest | ||
| // first, consecutive duplicates collapsed. Recalled with ArrowUp/ArrowDown. | ||
| const userMessageHistory = useMemo(() => { | ||
| const texts: string[] = []; | ||
| for (const msg of allMessages) { | ||
| if (msg.role !== "user") continue; | ||
| const text = (msg.parts ?? []) | ||
| .filter(part => part.kind === "text") | ||
| .map(part => (part as { text?: string }).text ?? "") | ||
| .join("") | ||
| .trim(); | ||
| if (text && texts[texts.length - 1] !== text) texts.push(text); | ||
| } | ||
| return texts; | ||
| }, [allMessages]); |
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.
ArrowUp on the composer's first line steps back through this session's previously sent messages (consecutive duplicates collapsed); ArrowDown steps forward and finally restores the unsent draft. Guards keep normal editing intact: recall only fires with a collapsed cursor on the first/last line, never during IME composition, and any manual edit or send exits history-browsing mode. The cursor lands at the end of each recalled message.