add heading commands

This commit is contained in:
Philipp Kühn
2020-11-18 12:24:41 +01:00
parent bf08653bba
commit 45a4562d4a
7 changed files with 41 additions and 31 deletions

View File

@@ -53,14 +53,24 @@ const Heading = Node.create({
addCommands() {
return {
/**
* Toggle a heading node
* Set a heading node
*/
heading: (options: { level: Level }): Command => ({ commands }) => {
if (!this.options.levels.includes(options.level)) {
setHeading: (attributes: { level: Level }): Command => ({ commands }) => {
if (!this.options.levels.includes(attributes.level)) {
return false
}
return commands.toggleBlockType('heading', 'paragraph', options)
return commands.setBlockType('heading', attributes)
},
/**
* Toggle a heading node
*/
toggleHeading: (attributes: { level: Level }): Command => ({ commands }) => {
if (!this.options.levels.includes(attributes.level)) {
return false
}
return commands.toggleBlockType('heading', 'paragraph', attributes)
},
}
},
@@ -69,7 +79,7 @@ const Heading = Node.create({
return this.options.levels.reduce((items, level) => ({
...items,
...{
[`Mod-Alt-${level}`]: () => this.editor.commands.setBlockType('heading', { level }),
[`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level }),
},
}), {})
},