feat(ui): shell-style message history recall in the chat composer#2284
Open
Feelings0220 wants to merge 2 commits into
Open
feat(ui): shell-style message history recall in the chat composer#2284Feelings0220 wants to merge 2 commits into
Feelings0220 wants to merge 2 commits into
Conversation
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]); |
mesutoezdil
reviewed
Jul 21, 2026
| if (historyIndexRef.current > 0) { | ||
| e.preventDefault(); | ||
| historyIndexRef.current -= 1; | ||
| const recalled = userMessageHistory[historyIndexRef.current]; |
Contributor
There was a problem hiding this comment.
historyIndexRef survives changes to userMessageHistory, so after a session reload shrinks the list this can read past the end and put undefined into the textarea, clamping the index to the current length would be safer.
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 Signed-off-by: Feelings0220 <124495386+Feelings0220@users.noreply.github.com>
Addresses review feedback: historyIndexRef survived changes to userMessageHistory, so after a session reload shrank the list a recall could read past the end and put undefined into the composer. Clamp the index to the current history length before using it. Signed-off-by: Feelings0220 <124495386+Feelings0220@users.noreply.github.com>
Feelings0220
force-pushed
the
ui/composer-history-upstream
branch
from
July 25, 2026 15:45
c4bb0e9 to
fca0c37
Compare
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.