mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-08 12:27:59 +08:00
23 lines
750 B
TypeScript
23 lines
750 B
TypeScript
|
import { Editor } from '../Editor'
|
||
|
import { TextSelection } from 'prosemirror-state'
|
||
|
|
||
|
declare module '../Editor' {
|
||
|
interface Editor {
|
||
|
setContent(content: string, emitUpdate: Boolean, parseOptions: any): Editor,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default function setContent(next: Function, editor: Editor, content: string, emitUpdate: Boolean = true, parseOptions: any = {}): void {
|
||
|
const { view, state, createDocument } = editor
|
||
|
const { doc, tr } = state
|
||
|
const document = createDocument(content, parseOptions)
|
||
|
const selection = TextSelection.create(doc, 0, doc.content.size)
|
||
|
const transaction = tr
|
||
|
.setSelection(selection)
|
||
|
.replaceSelectionWith(document, false)
|
||
|
.setMeta('preventUpdate', !emitUpdate)
|
||
|
|
||
|
view.dispatch(transaction)
|
||
|
next()
|
||
|
}
|