Skip to content

Commit 34bb4aa

Browse files
committed
Strip <think> blocks from copied chat message content
Updated clipboard copy functionality to remove <think> blocks from chat message content using a case-insensitive regex. This ensures that only the main message text is copied, regardless of autodetection.
1 parent a2b39bc commit 34bb4aa

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/lib/components/chat/ChatMessage.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@
6868
let editFormEl: HTMLFormElement | undefined = $state();
6969
7070
// Zero-config reasoning autodetection: detect <think> blocks in content
71-
const THINK_BLOCK_REGEX = /(<think>[\s\S]*?(?:<\/think>|$))/g;
71+
const THINK_BLOCK_REGEX = /(<think>[\s\S]*?(?:<\/think>|$))/gi;
7272
let hasClientThink = $derived(message.content.split(THINK_BLOCK_REGEX).length > 1);
7373
74+
// Strip think blocks for clipboard copy (always, regardless of detection)
75+
let contentWithoutThink = $derived.by(() =>
76+
message.content.replace(THINK_BLOCK_REGEX, "").trim()
77+
);
78+
7479
$effect(() => {
7580
if (isCopied) {
7681
setTimeout(() => {
@@ -214,7 +219,7 @@
214219
isCopied = true;
215220
}}
216221
classNames="btn rounded-sm p-1 text-sm text-gray-400 hover:text-gray-500 focus:ring-0 dark:text-gray-400 dark:hover:text-gray-300"
217-
value={message.content}
222+
value={contentWithoutThink}
218223
iconClassNames="text-xs"
219224
/>
220225
<button

0 commit comments

Comments
 (0)