diff --git a/src/renderer/src/components/RichEditor/useRichEditor.ts b/src/renderer/src/components/RichEditor/useRichEditor.ts index 576162fac7..536e7620bb 100644 --- a/src/renderer/src/components/RichEditor/useRichEditor.ts +++ b/src/renderer/src/components/RichEditor/useRichEditor.ts @@ -421,17 +421,21 @@ export const useRichEditor = (options: UseRichEditorOptions = {}): UseRichEditor // Default behavior for non-code blocks const text = event.clipboardData?.getData('text/plain') ?? '' if (text) { - const html = markdownToHtml(text) const { $from } = selection const atStartOfLine = $from.parentOffset === 0 const inEmptyParagraph = $from.parent.type.name === 'paragraph' && $from.parent.textContent === '' + // If pasting in the middle of a line, insert as plain text to avoid unwanted line breaks if (!atStartOfLine && !inEmptyParagraph) { - const cleanHtml = html.replace(/^
(.*?)<\/p>/s, '$1')
- editor.commands.insertContent(cleanHtml)
- } else {
- editor.commands.insertContent(html)
+ // Insert plain text without creating new paragraphs
+ const tr = view.state.tr.insertText(text, selection.from, selection.to)
+ view.dispatch(tr)
+ return true
}
+
+ // At start of line or in empty paragraph: convert markdown to HTML and insert
+ const html = markdownToHtml(text)
+ editor.commands.insertContent(html)
onPaste?.(html)
return true
}
diff --git a/src/renderer/src/utils/markdownConverter.ts b/src/renderer/src/utils/markdownConverter.ts
index 56f48cd465..51d684612d 100644
--- a/src/renderer/src/utils/markdownConverter.ts
+++ b/src/renderer/src/utils/markdownConverter.ts
@@ -81,7 +81,7 @@ export interface TaskListOptions {
const md = new MarkdownIt({
html: true, // Enable HTML tags in source
xhtmlOut: true, // Use '>' for single tags (
instead of
)
- breaks: true, // Preserve line breaks when pasting text
+ breaks: false,
linkify: false, // Autoconvert URL-like text to links
typographer: false // Enable smartypants and other sweet transforms
})