Skip to content
TypeScript

fix(web): send cited messages with Cmd+Enter (#9307)

Exotic77e35c561259
diff --git a/apps/web/src/components/ComposerCitationNode.tsx b/apps/web/src/components/ComposerCitationNode.tsx
index b54a0817310..ffaae589343 100644
--- a/apps/web/src/components/ComposerCitationNode.tsx
+++ b/apps/web/src/components/ComposerCitationNode.tsx
@@ -47,7 +47,8 @@ export type ComposerCitationCommentTarget = {
export const ComposerCitationCommentContext = createContext<{
openComment: ComposerCitationCommentTarget | null;
onOpenChange: (nodeKey: NodeKey, open: boolean) => void;
-}>({ openComment: null, onOpenChange: () => {} });
+ onSubmitAndSend: () => void;
+}>({ openComment: null, onOpenChange: () => {}, onSubmitAndSend: () => {} });
/** Consume a cite action once its controlled prompt has been committed to the editor. */
export function $consumeComposerCitationCommentRequest(requestRef: {
@@ -127,6 +128,11 @@ function ComposerCitationDecorator(props: { citation: AssistantCitation; nodeKey
commentContext.onOpenChange(props.nodeKey, open);
},
onSave: onSaveComment,
+ onSaveAndSend: (comment) => {
+ if (!onSaveComment(comment)) return false;
+ commentContext.onSubmitAndSend();
+ return true;
+ },
}}
onRemove={onRemove}
/>
diff --git a/apps/web/src/components/ComposerPromptEditor.tsx b/apps/web/src/components/ComposerPromptEditor.tsx
index 1676b4f01e7..695c5e3d085 100644
--- a/apps/web/src/components/ComposerPromptEditor.tsx
+++ b/apps/web/src/components/ComposerPromptEditor.tsx
@@ -924,6 +924,7 @@ interface ComposerPromptEditorProps {
onPageScrollKeyDown?: (key: "PageUp" | "PageDown") => void;
onPageScrollKeyUp?: (key: string) => void;
onPageScrollRelease?: () => void;
+ onCitationSubmitAndSend?: () => void;
onPaste: React.ClipboardEventHandler<HTMLElement>;
editorRef: React.RefObject<ComposerPromptEditorHandle | null>;
}
@@ -1571,6 +1572,7 @@ function ComposerPromptEditorInner({
onPageScrollKeyDown,
onPageScrollKeyUp,
onPageScrollRelease,
+ onCitationSubmitAndSend,
onPaste,
editorRef,
}: ComposerPromptEditorProps) {
@@ -1603,8 +1605,9 @@ function ComposerPromptEditorInner({
open ? { nodeKey } : current?.nodeKey === nodeKey ? null : current,
);
},
+ onSubmitAndSend: onCitationSubmitAndSend ?? (() => {}),
}),
- [openCitationComment],
+ [onCitationSubmitAndSend, openCitationComment],
);
const terminalContextActions = useMemo(
() => ({ onRemoveTerminalContext }),
@@ -1969,6 +1972,7 @@ export function ComposerPromptEditor({
onPageScrollKeyDown,
onPageScrollKeyUp,
onPageScrollRelease,
+ onCitationSubmitAndSend,
onPaste,
editorRef,
}: ComposerPromptEditorProps) {
@@ -2013,6 +2017,7 @@ export function ComposerPromptEditor({
onChange={onChange}
{...(onVisibleSelectionChange ? { onVisibleSelectionChange } : {})}
onPaste={onPaste}
+ {...(onCitationSubmitAndSend ? { onCitationSubmitAndSend } : {})}
editorRef={editorRef}
{...(onCommandKeyDown ? { onCommandKeyDown } : {})}
{...(onPageScrollKeyDown ? { onPageScrollKeyDown } : {})}
diff --git a/apps/web/src/components/chat/AssistantCitationChip.tsx b/apps/web/src/components/chat/AssistantCitationChip.tsx
index 4afaefe3f48..7582bb19c5c 100644
--- a/apps/web/src/components/chat/AssistantCitationChip.tsx
+++ b/apps/web/src/components/chat/AssistantCitationChip.tsx
@@ -42,6 +42,7 @@ export function AssistantCitationChip({
sourceAnchor?: AssistantCitationSourceAnchor | undefined;
onOpenChange: (open: boolean) => void;
onSave: (comment: string) => boolean;
+ onSaveAndSend?: (comment: string) => boolean;
};
}) {
const navigate = useNavigate();
@@ -158,6 +159,15 @@ export function AssistantCitationChip({
commentEditor.onOpenChange(false);
return true;
}}
+ {...(commentEditor.onSaveAndSend
+ ? {
+ onSubmitAndSend: (comment: string) => {
+ if (!commentEditor.onSaveAndSend?.(comment)) return false;
+ commentEditor.onOpenChange(false);
+ return true;
+ },
+ }
+ : {})}
onCancel={() => commentEditor.onOpenChange(false)}
/>
</PopoverPopup>
diff --git a/apps/web/src/components/chat/AssistantCitationCommentEditor.tsx b/apps/web/src/components/chat/AssistantCitationCommentEditor.tsx
index 3968d456865..4dc422210de 100644
--- a/apps/web/src/components/chat/AssistantCitationCommentEditor.tsx
+++ b/apps/web/src/components/chat/AssistantCitationCommentEditor.tsx
@@ -7,11 +7,13 @@ export function AssistantCitationCommentEditor({
citation,
inputRef,
onSubmit,
+ onSubmitAndSend,
onCancel,
}: {
citation: AssistantCitation;
inputRef?: Ref<HTMLTextAreaElement>;
onSubmit: (comment: string) => boolean;
+ onSubmitAndSend?: (comment: string) => boolean;
onCancel: () => void;
}) {
const [comment, setComment] = useState(citation.comment ?? "");
@@ -19,6 +21,14 @@ export function AssistantCitationCommentEditor({
const submit = () => {
if (!commentTooLong) onSubmit(comment);
};
+ const submitAndSend = () => {
+ if (commentTooLong) return;
+ if (onSubmitAndSend) {
+ onSubmitAndSend(comment);
+ } else {
+ onSubmit(comment);
+ }
+ };
return (
<div
@@ -35,7 +45,7 @@ export function AssistantCitationCommentEditor({
<textarea
ref={inputRef}
aria-label="Comment on selected text"
- aria-description="Enter to save the citation comment; Shift+Enter for a new line."
+ aria-description="Enter to save the citation comment; Command/Ctrl+Enter to save and send; Shift+Enter for a new line."
aria-invalid={commentTooLong || undefined}
placeholder="Add an optional comment..."
rows={2}
@@ -50,7 +60,11 @@ export function AssistantCitationCommentEditor({
event.keyCode !== 229
) {
event.preventDefault();
- submit();
+ if (event.metaKey || event.ctrlKey) {
+ submitAndSend();
+ } else {
+ submit();
+ }
}
}}
/>
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 93ae287c702..b24fb16c523 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -2824,6 +2824,15 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
shouldBlurMobileComposerOnSubmit,
],
);
+ const submitCitationAndSend = useCallback(() => {
+ const intent = composerSubmissionIntentForEnter({
+ isMobileViewport,
+ shiftKey: false,
+ modifierKey: true,
+ isDraftThread: routeKind === "draft",
+ });
+ submitComposer(undefined, intent ?? "foreground");
+ }, [isMobileViewport, routeKind, submitComposer]);
const compactThreadContext = useCallback(() => {
if (
compactDisabled ||
@@ -5246,6 +5255,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
onPageScrollKeyDown={onPageScrollKeyDown}
onPageScrollKeyUp={onPageScrollKeyUp}
onPageScrollRelease={onPageScrollRelease}
+ onCitationSubmitAndSend={submitCitationAndSend}
onPaste={onComposerPaste}
placeholder={
isComposerApprovalState