Files
tiptap/packages/core/src/commands/setContent.ts
Philipp Kühn 13a314e123 refactoring
2020-11-16 21:42:35 +01:00

18 lines
553 B
TypeScript

import { TextSelection } from 'prosemirror-state'
import { Command } from '../types'
export default (content: string, emitUpdate: Boolean = false, parseOptions = {}): Command => ({ tr, editor, dispatch }) => {
const { createDocument } = editor
const { doc } = tr
const document = createDocument(content, parseOptions)
const selection = TextSelection.create(doc, 0, doc.content.size)
if (dispatch) {
tr.setSelection(selection)
.replaceSelectionWith(document, false)
.setMeta('preventUpdate', !emitUpdate)
}
return true
}