diff --git a/docs/src/demos/Examples/Basic/index.vue b/docs/src/demos/Examples/Basic/index.vue index 292a7cba..75b7ac48 100644 --- a/docs/src/demos/Examples/Basic/index.vue +++ b/docs/src/demos/Examples/Basic/index.vue @@ -22,22 +22,22 @@ paragraph - + h1 - + h2 - + h3 - + h4 - + h5 - + h6 diff --git a/docs/src/demos/Examples/CollaborativeEditing/index.vue b/docs/src/demos/Examples/CollaborativeEditing/index.vue index ca8e5e09..56981074 100644 --- a/docs/src/demos/Examples/CollaborativeEditing/index.vue +++ b/docs/src/demos/Examples/CollaborativeEditing/index.vue @@ -22,22 +22,22 @@ paragraph - + h1 - + h2 - + h3 - + h4 - + h5 - + h6 diff --git a/docs/src/demos/Examples/CollaborativeEditingWs/index.vue b/docs/src/demos/Examples/CollaborativeEditingWs/index.vue index 5ae43826..a80a2e24 100644 --- a/docs/src/demos/Examples/CollaborativeEditingWs/index.vue +++ b/docs/src/demos/Examples/CollaborativeEditingWs/index.vue @@ -22,22 +22,22 @@ paragraph - + h1 - + h2 - + h3 - + h4 - + h5 - + h6 diff --git a/docs/src/demos/Examples/Formatting/index.vue b/docs/src/demos/Examples/Formatting/index.vue index b2ba788f..97b7a521 100644 --- a/docs/src/demos/Examples/Formatting/index.vue +++ b/docs/src/demos/Examples/Formatting/index.vue @@ -7,13 +7,13 @@ italic - + h1 - + h2 - + h3 diff --git a/docs/src/demos/Guide/BuildYourEditor/index.vue b/docs/src/demos/Guide/BuildYourEditor/index.vue index afd4cbef..0d382c14 100644 --- a/docs/src/demos/Guide/BuildYourEditor/index.vue +++ b/docs/src/demos/Guide/BuildYourEditor/index.vue @@ -16,10 +16,10 @@ italic - + h1 - + h2 diff --git a/docs/src/demos/Nodes/Heading/index.vue b/docs/src/demos/Nodes/Heading/index.vue index b8d47e8e..cbeda076 100644 --- a/docs/src/demos/Nodes/Heading/index.vue +++ b/docs/src/demos/Nodes/Heading/index.vue @@ -1,12 +1,12 @@ - + h1 - + h2 - + h3 diff --git a/packages/extension-heading/src/index.ts b/packages/extension-heading/src/index.ts index c02b8a81..a9a1ee39 100644 --- a/packages/extension-heading/src/index.ts +++ b/packages/extension-heading/src/index.ts @@ -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 }), }, }), {}) },