fix: simplify text pasting in editor and insert a new line after upload placeholder

This commit is contained in:
codytseng
2025-07-11 11:50:35 +08:00
parent 67659a302b
commit 9a5008080a
2 changed files with 5 additions and 11 deletions

View File

@@ -75,15 +75,8 @@ export const ClipboardAndDropHandler = Extension.create<ClipboardAndDropHandlerO
}
} else if (item.kind === 'string' && item.type === 'text/plain') {
item.getAsString((text) => {
const { schema } = view.state
const parts = text.split('\n')
const nodes = []
for (let i = 0; i < parts.length; i++) {
if (i > 0) nodes.push(schema.nodes.hardBreak.create())
if (parts[i]) nodes.push(schema.text(parts[i]))
}
const fragment = schema.nodes.paragraph.create(null, nodes)
const tr = view.state.tr.replaceSelectionWith(fragment)
const textNode = view.state.schema.text(text)
const tr = view.state.tr.replaceSelectionWith(textNode)
view.dispatch(tr)
})
handled = true
@@ -107,7 +100,9 @@ async function uploadFile(view: EditorView, file: File, options: ClipboardAndDro
const placeholder = `[Uploading "${name}"...]`
const uploadingNode = view.state.schema.text(placeholder)
const tr = view.state.tr.replaceSelectionWith(uploadingNode)
const paragraph = view.state.schema.nodes.paragraph.create()
let tr = view.state.tr.replaceSelectionWith(uploadingNode)
tr = tr.insert(tr.selection.to, paragraph)
view.dispatch(tr)
mediaUpload

View File

@@ -53,7 +53,6 @@ export default function Uploader({
style={{ display: 'none' }}
onChange={handleFileChange}
accept={accept}
multiple
/>
</div>
)