add clearContent command

This commit is contained in:
Philipp Kühn
2020-03-29 23:24:37 +02:00
parent add9090d39
commit b30f5c3320
3 changed files with 19 additions and 5 deletions

View File

@@ -54,6 +54,7 @@ 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

View File

@@ -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()
}

View File

@@ -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,7 +11,7 @@ export default function setContent(
next: Function,
editor: Editor,
content = null,
emitUpdate = true,
emitUpdate = false,
parseOptions = {},
): void {
if (content === null) {