remove insertText from insertContent

This commit is contained in:
Philipp Kühn
2021-05-05 14:13:58 +02:00
parent 63902d4bdb
commit b5c51723ea
3 changed files with 18 additions and 23 deletions

View File

@@ -1,7 +1,10 @@
import createNodeFromContent from '../helpers/createNodeFromContent'
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
import {
Command, RawCommands, Content, Range,
Command,
RawCommands,
Content,
Range,
} from '../types'
declare module '@tiptap/core' {
@@ -17,19 +20,12 @@ declare module '@tiptap/core' {
export const insertContentAt: RawCommands['insertContentAt'] = (range, value) => ({ tr, dispatch, editor }) => {
if (dispatch) {
const content = createNodeFromContent(value, editor.schema)
if (typeof content === 'string') {
tr.insertText(content)
tr.scrollIntoView()
return true
}
if (range.from !== range.to) {
tr.delete(range.from, range.to)
tr.deleteRange(range.from, range.to)
}
const content = createNodeFromContent(value, editor.schema)
tr.insert(range.from, content)
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
tr.scrollIntoView()