The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(chat): right-click Copy text copies what Ctrl+C copies, the source is Copy as Markdown
purplef1e65b61eeeb
diff --git a/src/components/chat/MessageBubble.tsx b/src/components/chat/MessageBubble.tsxindex 00c056b0..83febd88 100644--- a/src/components/chat/MessageBubble.tsx+++ b/src/components/chat/MessageBubble.tsx@@ -30,6 +30,7 @@ import { extractToolCallsFromContent, looksLikeToolIntent } from '../../lib/toolimport { isAgentCompatible } from '../../lib/model-compatibility'import { ContextMenu } from '../ui/ContextMenu'import { buildMessageMenu, type MessageMenuHandlers } from '../ui/menu-actions'+import { plainTextToCopy } from '../../lib/copy-plain'import { MONOGRAM, MONOGRAM_INVERT } from '../layout/brand'import { AVATAR_SLOT, MODEL_MARK, MODEL_MARK_SLOT } from './avatar-slot'import { MOTION_S } from '../ui/motion'@@ -91,7 +92,10 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, pconst [isEditing, setIsEditing] = useState(false)const [editContent, setEditContent] = useState('')const [confirmDelete, setConfirmDelete] = useState(false)- const [menu, setMenu] = useState<{ x: number; y: number } | null>(null)+ // `text` is what "Copy text" will copy, taken when the menu opens: the+ // click into the menu may clear the selection.+ const [menu, setMenu] = useState<{ x: number; y: number; text: string } | null>(null)+ const columnRef = useRef<HTMLDivElement>(null)const editRef = useRef<HTMLTextAreaElement>(null)const isUser = message.role === 'user'@@ -199,6 +203,14 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, psetTimeout(() => setCopied(false), 2000)}+ // Right-click "Copy text": what Ctrl+C would give (lib/copy-plain.ts).+ const handleCopyText = () => {+ if (!menu) return+ navigator.clipboard.writeText(menu.text)+ setCopied(true)+ setTimeout(() => setCopied(false), 2000)+ }+const startEdit = () => {// User: edit the short slash command, not its expanded instruction.// Assistant: edit what the model actually said.@@ -268,6 +280,7 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, pconst canEdit = !readOnly && ((isUser && !!onEdit) || canEditAssistant)const actions: MessageMenuHandlers = {copy: handleCopy,+ copyText: handleCopyText,edit: canEdit ? startEdit : null,regenerate: !isUser && onRegenerate ? () => onRegenerate(message.id) : null,branch: onBranch ? () => onBranch(message.id) : null,@@ -327,7 +340,8 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, ponContextMenu={(e) => {if (!actionsAvailable) returne.preventDefault()- setMenu({ x: e.clientX, y: e.clientY })+ const text = columnRef.current ? plainTextToCopy(columnRef.current, window.getSelection()) : ''+ setMenu({ x: e.clientX, y: e.clientY, text })}}initial={{ opacity: 0, y: 6 }}animate={{ opacity: 1, y: 0 }}@@ -348,7 +362,7 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, p{/* A reply with a Create order takes the full width in a narrow window:the card and the result need the room. */}- <div className={(hasCreateOrder ? 'min-w-0 flex-1 sm:flex-none sm:max-w-[80%]' : 'max-w-[80%]') + ' space-y-0.5'}>+ <div ref={columnRef} className={(hasCreateOrder ? 'min-w-0 flex-1 sm:flex-none sm:max-w-[80%]' : 'max-w-[80%]') + ' space-y-0.5'}>{/* Name the model that produced this answer. Group chats have alwaysdone this; since the R5 re-measure (2026-08-30) every assistantturn carries it, because the app had no model name at a single@@ -445,7 +459,7 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, pconst istSchluss = gruppenIndex === gruppen.length - 1return (<div key={block.id} className="px-1 py-0.5">- <div className={'text-[0.8rem] leading-relaxed' + (isStreaming && istSchluss ? ' lu-caret' : '')}>+ <div data-copy-text className={'text-[0.8rem] leading-relaxed' + (isStreaming && istSchluss ? ' lu-caret' : '')}><MarkdownRenderer content={isStreaming && istSchluss ? closeOpenMarkdown(clean) : clean} /></div></div>@@ -553,7 +567,7 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, p// long expanded instruction held in content (which drives the model).// The same holds for a message with files: content carries their// summaries for the model, the bubble shows what was typed.- <p className="text-[0.78rem] leading-relaxed text-gray-800 dark:text-gray-200 whitespace-pre-wrap wrap-anywhere">{message.displayContent || message.content}</p>+ <p data-copy-text className="text-[0.78rem] leading-relaxed text-gray-800 dark:text-gray-200 whitespace-pre-wrap wrap-anywhere">{message.displayContent || message.content}</p>) : (// Answer-blocks (when present) already rendered the per-iteration// text chronologically above; skip message.content here to avoid@@ -570,7 +584,7 @@ function MessageBubbleImpl({ message, onRegenerate, onRegenerateRound, onEdit, p// eine reine Funktion des vorhandenen `isStreaming`-Props —// kein Zustand, kein Timer, keine Subscription, also auch// kein Rerender, den der Stream nicht ohnehin ausloest.- <div className={'text-[0.78rem] leading-relaxed' + (isStreaming ? ' lu-caret' : '')}>+ <div data-copy-text className={'text-[0.78rem] leading-relaxed' + (isStreaming ? ' lu-caret' : '')}>{/* While it streams, an open ` or ** is closed for the frame(lib/streaming-markdown.ts); the stored text is untouched. */}<MarkdownRenderer content={isStreaming ? closeOpenMarkdown(cleanContent) : cleanContent} />diff --git a/src/components/chat/__tests__/copy-text-is-what-ctrl-c-gives.test.tsx b/src/components/chat/__tests__/copy-text-is-what-ctrl-c-gives.test.tsxnew file mode 100644index 00000000..bb66f821--- /dev/null+++ b/src/components/chat/__tests__/copy-text-is-what-ctrl-c-gives.test.tsx@@ -0,0 +1,60 @@+// @vitest-environment jsdom+/**+ * Discord #bug-reports, 30.10.2026: right-click on an answer, "Copy text",+ * paste: "**bold** words", Markdown and all. Ctrl+C on the same answer gives+ * the plain text. "Copy text" now gives what Ctrl+C gives: the selection+ * inside the message, or the text as shown. The Markdown source is one entry+ * further down, "Copy as Markdown", the same as the Copy button.+ *+ * Run: npx vitest run src/components/chat/__tests__/copy-text-is-what-ctrl-c-gives.test.tsx+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { MessageBubble } from '../MessageBubble'+import type { Message } from '../../../types/chat'++const SOURCE = 'The **capital** of France is *Paris*.\n\n- one\n- two'+const answer: Message = { id: 'a1', role: 'assistant', content: SOURCE, timestamp: 1, modelId: 'ollama::qwen2.5:0.5b' }++const written: string[] = []+beforeEach(() => {+ written.length = 0+ Object.defineProperty(navigator, 'clipboard', { value: { writeText: vi.fn(async (t: string) => { written.push(t) }) }, configurable: true })+})+afterEach(() => { cleanup(); window.getSelection()?.removeAllRanges() })++function openMenu() {+ const words = screen.getByText('capital')+ fireEvent.contextMenu(words)+ return screen.getByRole('menu')+}++describe('right-click "Copy text" on an answer', () => {+ it('copies the shown text, no Markdown marks', () => {+ render(<MessageBubble message={answer} />)+ openMenu()+ fireEvent.click(screen.getByRole('menuitem', { name: 'Copy text' }))+ expect(written).toHaveLength(1)+ expect(written[0]).not.toContain('**')+ expect(written[0]).not.toContain('*Paris*')+ expect(written[0]).toContain('The capital of France is Paris.')+ expect(written[0]).toContain('one')+ })++ it('copies the selection when words in the message are selected', () => {+ render(<MessageBubble message={answer} />)+ const range = document.createRange()+ range.selectNodeContents(screen.getByText('capital'))+ window.getSelection()!.addRange(range)+ openMenu()+ fireEvent.click(screen.getByRole('menuitem', { name: 'Copy text' }))+ expect(written).toEqual(['capital'])+ })++ it('"Copy as Markdown" keeps the source, like the Copy button', () => {+ render(<MessageBubble message={answer} />)+ openMenu()+ fireEvent.click(screen.getByRole('menuitem', { name: 'Copy as Markdown' }))+ expect(written).toEqual([SOURCE])+ })+})diff --git a/src/components/ui/menu-actions.ts b/src/components/ui/menu-actions.tsindex 60bfc6d9..dc6eea49 100644--- a/src/components/ui/menu-actions.ts+++ b/src/components/ui/menu-actions.ts@@ -37,7 +37,12 @@ export interface MenuAction {* Nachricht, oder es läuft gerade eine Antwort).*/export interface MessageMenuHandlers {+ /** The Copy button of the bar: the message as Markdown. */readonly copy: () => void+ /** Right-click only: the selected or shown text, as Ctrl+C gives it+ * (lib/copy-plain.ts). With it, the button's copy becomes "Copy as+ * Markdown" in the menu. */+ readonly copyText?: () => voidreadonly edit: (() => void) | nullreadonly regenerate: (() => void) | null/** GH #174: a new chat that ends with this message. */@@ -57,7 +62,13 @@ export function buildMessageMenu(h: MessageMenuHandlers, s: MessageMenuState): Mconst out: MenuAction[] = []if (h.edit) out.push({ id: 'edit', label: 'Edit', run: h.edit })if (h.regenerate) out.push({ id: 'regenerate', label: 'Regenerate', run: h.regenerate })- out.push({ id: 'copy', label: s.copied ? 'Copied' : 'Copy text', run: h.copy })+ if (h.copyText) {+ // Discord 30.10.2026: "Copy text" pasted ** around bold words.+ out.push({ id: 'copy', label: s.copied ? 'Copied' : 'Copy text', run: h.copyText })+ out.push({ id: 'copy-markdown', label: 'Copy as Markdown', run: h.copy })+ } else {+ out.push({ id: 'copy', label: s.copied ? 'Copied' : 'Copy text', run: h.copy })+ }if (h.branch) out.push({ id: 'branch', label: 'Branch from here', run: h.branch })// Die Beschriftung sagt dasselbe wie der `title` des Knopfes: der erste// Aufruf schärft nur, gelöscht wird erst beim zweiten.diff --git a/src/lib/copy-plain.ts b/src/lib/copy-plain.tsnew file mode 100644index 00000000..f2bc7192--- /dev/null+++ b/src/lib/copy-plain.ts@@ -0,0 +1,21 @@+/**+ * What "Copy text" in the context menu of a chat message puts on the+ * clipboard (Discord #bug-reports 30.10.2026): the same as Ctrl+C, never+ * the Markdown source. The words the user selected inside the message, or,+ * with nothing selected there, the text of the message as it is shown. The+ * source stays one entry further down, "Copy as Markdown".+ *+ * `root` is the message; the parts that show its text carry+ * `data-copy-text`, so names, chips, sources and the action bar stay out.+ */+export function plainTextToCopy(root: Element, selection: Selection | null): string {+ if (selection && !selection.isCollapsed && selection.rangeCount > 0) {+ const range = selection.getRangeAt(0)+ if (root.contains(range.commonAncestorContainer)) return selection.toString()+ }+ return [...root.querySelectorAll<HTMLElement>('[data-copy-text]')]+ // innerText is the text as laid out, as Ctrl+C copies it; jsdom has none.+ .map((el) => (el.innerText ?? el.textContent ?? '').trim())+ .filter(Boolean)+ .join('\n\n')+}