diff --git a/packages/tiptap-core/src/Editor.ts b/packages/tiptap-core/src/Editor.ts index 4a18317e..a309f9f9 100644 --- a/packages/tiptap-core/src/Editor.ts +++ b/packages/tiptap-core/src/Editor.ts @@ -54,7 +54,8 @@ export class Editor extends EventEmitter { this.registerCommand('insertText', require('./commands/insertText').default) this.registerCommand('insertHTML', require('./commands/insertHTML').default) this.registerCommand('setContent', require('./commands/setContent').default) - + this.registerCommand('clearContent', require('./commands/clearContent').default) + if (this.options.injectCSS) { injectCSS(require('./style.css')) } @@ -84,7 +85,7 @@ export class Editor extends EventEmitter { } this.commands[name] = this.chainCommand((...args: any) => { - return new Promise(resolve => callback(resolve, this, ...args)) + return new Promise(resolve => callback(resolve, this.proxy, ...args)) }) return this.proxy diff --git a/packages/tiptap-core/src/commands/clearContent.ts b/packages/tiptap-core/src/commands/clearContent.ts new file mode 100644 index 00000000..db8c2a6a --- /dev/null +++ b/packages/tiptap-core/src/commands/clearContent.ts @@ -0,0 +1,13 @@ +import { Editor } from '../Editor' +import { TextSelection } from 'prosemirror-state' + +declare module '../Editor' { + interface Editor { + clearContent(emitUpdate?: Boolean): Editor, + } +} + +export default function clearContent(next: Function, editor: Editor, emitUpdate = false): void { + editor.setContent('', emitUpdate) + next() +} diff --git a/packages/tiptap-core/src/commands/setContent.ts b/packages/tiptap-core/src/commands/setContent.ts index 427fbca8..472c7ae5 100644 --- a/packages/tiptap-core/src/commands/setContent.ts +++ b/packages/tiptap-core/src/commands/setContent.ts @@ -3,7 +3,7 @@ import { TextSelection } from 'prosemirror-state' declare module '../Editor' { interface Editor { - setContent(content: string, emitUpdate: Boolean, parseOptions: any): Editor, + setContent(content: string, emitUpdate?: Boolean, parseOptions?: any): Editor, } } @@ -11,14 +11,14 @@ export default function setContent( next: Function, editor: Editor, content = null, - emitUpdate = true, + emitUpdate = false, parseOptions = {}, ): void { if (content === null) { next() return } - + const { view, state, createDocument } = editor const { doc, tr } = state const document = createDocument(content, parseOptions)