diff --git a/docs/src/data/posts/commands.md b/docs/src/data/posts/commands.md index 8e6f27da..59492f46 100644 --- a/docs/src/data/posts/commands.md +++ b/docs/src/data/posts/commands.md @@ -4,6 +4,10 @@ Clear the whole document. +## .deleteSelection() + +Delete the selection, if there is one. + ## .focus() Focus the editor at the given position. diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index 8b7a0b3f..add81585 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -66,6 +66,7 @@ export class Editor extends EventEmitter { this.createSchema() this.createView() this.registerCommand('clearContent', require('./commands/clearContent').default) + this.registerCommand('deleteSelection', require('./commands/deleteSelection').default) this.registerCommand('focus', require('./commands/focus').default) this.registerCommand('insertHTML', require('./commands/insertHTML').default) this.registerCommand('insertText', require('./commands/insertText').default) diff --git a/packages/core/src/commands/deleteSelection.ts b/packages/core/src/commands/deleteSelection.ts new file mode 100644 index 00000000..1a67e086 --- /dev/null +++ b/packages/core/src/commands/deleteSelection.ts @@ -0,0 +1,15 @@ +import { Editor } from '../Editor' +import { deleteSelection } from 'prosemirror-commands' + +type DeleteSelection = () => any + +declare module '../Editor' { + interface Editor { + deleteSelection: DeleteSelection, + } +} + +export default (next: Function, { state, view }: Editor): DeleteSelection => () => { + deleteSelection(state, view.dispatch) + next() +}