Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/web/src/components/ComposerPromptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ export interface ComposerPromptEditorHandle {
focus: () => void;
focusAt: (cursor: number) => void;
focusAtEnd: () => void;
insertText: (text: string) => void;
readSnapshot: () => {
value: string;
cursor: number;
Expand Down Expand Up @@ -1691,9 +1692,19 @@ function ComposerPromptEditorInner({
),
);
},
insertText: (text: string) => {
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.insertRawText(text);
return;
}
$getRoot().selectEnd().insertRawText(text);
});
},
readSnapshot,
}),
[focusAt, readSnapshot],
[editor, focusAt, readSnapshot],
);

const handleEditorChange = useCallback((editorState: EditorState) => {
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ function isInsideComposerFloatingLayer(element: Element): boolean {
return element.closest(COMPOSER_FLOATING_LAYER_SELECTOR) !== null;
}

/** A pasted link the user meant to keep, as opposed to accessory clipboard text. */
function isHttpUrlText(text: string): boolean {
if (!/^https?:\/\//i.test(text)) return false;
try {
const url = new URL(text);
return url.protocol === "http:" || url.protocol === "https:";
} catch {
return false;
}
}

const ComposerFooterModeControls = memo(function ComposerFooterModeControls(props: {
showInteractionModeToggle: boolean;
interactionMode: ProviderInteractionMode;
Expand Down Expand Up @@ -2392,6 +2403,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
if (imageFiles.length === 0) return;
event.preventDefault();
void addComposerImages(imageFiles);
// Copying a link from a browser or chat app often puts the URL text and a
// preview image on the clipboard together. preventDefault above suppresses
// the native text insertion, so re-insert the text half instead of
// silently dropping it with the attachment. Only URL-shaped text
// qualifies: OS file copies and image copies can carry accessory
// text/plain (file names, local paths) the user never meant to insert.
const text = event.clipboardData.getData("text/plain").trim();
if (isHttpUrlText(text)) {
composerEditorRef.current?.insertText(text);
}
};

const onComposerDragEnter = (event: React.DragEvent<HTMLDivElement>) => {
Expand Down
Loading