fix: simplify text pasting in editor and insert a new line after upload placeholder
This commit is contained in:
@@ -75,15 +75,8 @@ export const ClipboardAndDropHandler = Extension.create<ClipboardAndDropHandlerO
|
|||||||
}
|
}
|
||||||
} else if (item.kind === 'string' && item.type === 'text/plain') {
|
} else if (item.kind === 'string' && item.type === 'text/plain') {
|
||||||
item.getAsString((text) => {
|
item.getAsString((text) => {
|
||||||
const { schema } = view.state
|
const textNode = view.state.schema.text(text)
|
||||||
const parts = text.split('\n')
|
const tr = view.state.tr.replaceSelectionWith(textNode)
|
||||||
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)
|
|
||||||
view.dispatch(tr)
|
view.dispatch(tr)
|
||||||
})
|
})
|
||||||
handled = true
|
handled = true
|
||||||
@@ -107,7 +100,9 @@ async function uploadFile(view: EditorView, file: File, options: ClipboardAndDro
|
|||||||
|
|
||||||
const placeholder = `[Uploading "${name}"...]`
|
const placeholder = `[Uploading "${name}"...]`
|
||||||
const uploadingNode = view.state.schema.text(placeholder)
|
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)
|
view.dispatch(tr)
|
||||||
|
|
||||||
mediaUpload
|
mediaUpload
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ export default function Uploader({
|
|||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}
|
||||||
onChange={handleFileChange}
|
onChange={handleFileChange}
|
||||||
accept={accept}
|
accept={accept}
|
||||||
multiple
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user