add removeMarks command
This commit is contained in:
@@ -66,6 +66,7 @@ export class Editor extends EventEmitter {
|
||||
this.registerCommand('insertHTML', require('./commands/insertHTML').default)
|
||||
this.registerCommand('setContent', require('./commands/setContent').default)
|
||||
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
||||
this.registerCommand('removeMarks', require('./commands/removeMarks').default)
|
||||
|
||||
if (this.options.injectCSS) {
|
||||
this.css = injectCSS(require('./style.css'))
|
||||
|
||||
28
packages/core/src/commands/removeMarks.ts
Normal file
28
packages/core/src/commands/removeMarks.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Editor } from '../Editor'
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
removeMarks(): Editor,
|
||||
}
|
||||
}
|
||||
|
||||
export default function removeMarks(next: Function, editor: Editor): void {
|
||||
const { state, view, schema } = editor
|
||||
const { selection, tr } = state
|
||||
const { from, to, empty } = selection
|
||||
let transaction = tr
|
||||
|
||||
if (empty) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
Object
|
||||
.entries(schema.marks)
|
||||
.forEach(([name, mark]) => {
|
||||
transaction.removeMark(from, to, mark)
|
||||
})
|
||||
|
||||
view.dispatch(transaction)
|
||||
next()
|
||||
}
|
||||
Reference in New Issue
Block a user