-
-
Notifications
You must be signed in to change notification settings - Fork 253
feat(messages): add quote action for composer #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,8 +60,21 @@ type MessagesProps = { | |
| onPlanAccept?: () => void; | ||
| onPlanSubmitChanges?: (changes: string) => void; | ||
| onOpenThreadLink?: (threadId: string) => void; | ||
| onQuoteMessage?: (text: string) => void; | ||
| }; | ||
|
|
||
| function toMarkdownQuote(text: string): string { | ||
| const trimmed = text.trim(); | ||
| if (!trimmed) { | ||
| return ""; | ||
| } | ||
| return trimmed | ||
| .split(/\r?\n/) | ||
| .map((line) => `> ${line}`) | ||
| .join("\n") | ||
| .concat("\n\n"); | ||
|
Comment on lines
+71
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The generated quote text always begins with Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| export const Messages = memo(function Messages({ | ||
| items, | ||
| threadId, | ||
|
|
@@ -82,6 +95,7 @@ export const Messages = memo(function Messages({ | |
| onPlanAccept, | ||
| onPlanSubmitChanges, | ||
| onOpenThreadLink, | ||
| onQuoteMessage, | ||
| }: MessagesProps) { | ||
| const bottomRef = useRef<HTMLDivElement | null>(null); | ||
| const containerRef = useRef<HTMLDivElement | null>(null); | ||
|
|
@@ -259,6 +273,20 @@ export const Messages = memo(function Messages({ | |
| [], | ||
| ); | ||
|
|
||
| const handleQuoteMessage = useCallback( | ||
| (item: Extract<ConversationItem, { kind: "message" }>) => { | ||
| if (!onQuoteMessage) { | ||
| return; | ||
| } | ||
| const quoteText = toMarkdownQuote(item.text); | ||
| if (!quoteText) { | ||
| return; | ||
| } | ||
| onQuoteMessage(quoteText); | ||
| }, | ||
| [onQuoteMessage], | ||
| ); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const container = containerRef.current; | ||
| const shouldScroll = | ||
|
|
@@ -353,6 +381,7 @@ export const Messages = memo(function Messages({ | |
| item={item} | ||
| isCopied={isCopied} | ||
| onCopy={handleCopyMessage} | ||
| onQuote={onQuoteMessage ? handleQuoteMessage : undefined} | ||
| codeBlockCopyUseModifier={codeBlockCopyUseModifier} | ||
| showMessageFilePath={showMessageFilePath} | ||
| workspacePath={workspacePath} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line passes
options.onInsertComposerTextdirectly intoMessages, but that callback is created byuseComposerInsertwithdraftTextin its dependency list (src/features/app/hooks/useComposerInsert.ts), so its identity changes on every keystroke. As a result,Messages(and all markdown rows) re-render while typing even when message data is unchanged, which can noticeably degrade input responsiveness in long threads.Useful? React with 👍 / 👎.