Skip to content

Commit 1417024

Browse files
committed
fix: 修复无法正确复制公式、mermaid 图表等内容
1 parent d8d842d commit 1417024

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/app/core/main/chat/chat-send.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export const ChatSend = forwardRef<{ sendChat: () => void }, ChatSendProps>(({ i
337337
if (quoteData) {
338338
const { fileName, startLine, endLine, fullContent } = quoteData
339339
let lineInfo = ''
340-
let hasValidLineNumbers = startLine !== -1 && endLine !== -1
340+
const hasValidLineNumbers = startLine !== -1 && endLine !== -1
341341

342342
if (hasValidLineNumbers) {
343343
if (startLine === endLine) {

src/app/core/main/editor/markdown/tiptap-editor.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const PasteMarkdown = Extension.create({
8181
},
8282
})
8383

84+
8485
// 简单的启发式函数:检查文本是否看起来像 Markdown
8586
function looksLikeMarkdown(text: string): boolean {
8687
return (
@@ -343,6 +344,29 @@ export function TipTapEditor({
343344
}
344345
}, [editor])
345346

347+
// Handle copy event to output Markdown format
348+
useEffect(() => {
349+
if (!editor) return
350+
351+
const handleCopy = (event: ClipboardEvent) => {
352+
// Get the selected content as Markdown
353+
const markdown = editor.getMarkdown()
354+
355+
// Write Markdown to clipboard
356+
if (event.clipboardData) {
357+
event.clipboardData.setData('text/plain', markdown)
358+
event.preventDefault()
359+
}
360+
}
361+
362+
const dom = editor.view.dom
363+
dom.addEventListener('copy', handleCopy as EventListener)
364+
365+
return () => {
366+
dom.removeEventListener('copy', handleCopy as EventListener)
367+
}
368+
}, [editor])
369+
346370
// Handle AI Polish - improve selected text (with streaming and suggestion mode)
347371
const handleAIPolish = useCallback(async () => {
348372
if (!editor) return

0 commit comments

Comments
 (0)