add paragraph command and keyboard shortcut

This commit is contained in:
Hans Pagel
2020-09-24 15:27:29 +02:00
parent 8011cd45bd
commit d7db24a199
2 changed files with 13 additions and 0 deletions

View File

@@ -28,6 +28,9 @@
<button @click="editor.chain().focus().codeBlock().run()" :class="{ 'is-active': editor.isActive('codeBlock') }"> <button @click="editor.chain().focus().codeBlock().run()" :class="{ 'is-active': editor.isActive('codeBlock') }">
code block code block
</button> </button>
<button @click="editor.chain().focus().paragraph().run()" :class="{ 'is-active': editor.isActive('paragraph') }">
paragraph
</button>
<button @click="editor.chain().focus().heading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }"> <button @click="editor.chain().focus().heading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
h1 h1
</button> </button>

View File

@@ -10,4 +10,14 @@ export default new Node()
toDOM: () => ['p', 0], toDOM: () => ['p', 0],
// toVue: ParagraphComponent, // toVue: ParagraphComponent,
})) }))
.commands(({ name }) => ({
[name]: () => ({ commands }) => {
return commands.toggleNode(name, 'paragraph')
},
}))
.keys(({ editor, name }) => ({
// Exception: TS2339: Property 'paragraph' does not exist on type 'Editor'.
// 'Mod-Alt-0': () => editor.paragraph(),
'Mod-Alt-0': () => editor.toggleNode(name, 'paragraph'),
}))
.create() .create()