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('insertHTML', require('./commands/insertHTML').default)
|
||||||
this.registerCommand('setContent', require('./commands/setContent').default)
|
this.registerCommand('setContent', require('./commands/setContent').default)
|
||||||
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
||||||
|
this.registerCommand('removeMarks', require('./commands/removeMarks').default)
|
||||||
|
|
||||||
if (this.options.injectCSS) {
|
if (this.options.injectCSS) {
|
||||||
this.css = injectCSS(require('./style.css'))
|
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()
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div v-if="editor">
|
<div v-if="editor">
|
||||||
|
<button @click="editor.focus().removeMarks()">
|
||||||
|
clear formatting
|
||||||
|
</button>
|
||||||
<button @click="editor.focus().undo()">
|
<button @click="editor.focus().undo()">
|
||||||
undo
|
undo
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user