From ff9c260e3cacee4d903f160c8573f97026a01934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A2=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Thu, 15 Feb 2024 15:57:09 +0100 Subject: [PATCH] feat: heading button that resets heading back to paragraph --- src/extensions/yfm/YfmHeading/commands.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/extensions/yfm/YfmHeading/commands.ts b/src/extensions/yfm/YfmHeading/commands.ts index ff7cf012..8d37174e 100644 --- a/src/extensions/yfm/YfmHeading/commands.ts +++ b/src/extensions/yfm/YfmHeading/commands.ts @@ -2,24 +2,19 @@ import {setBlockType} from 'prosemirror-commands'; import type {Command} from 'prosemirror-state'; import {findParentNodeOfType} from 'prosemirror-utils'; +import {toParagraph} from '../../../extensions/base'; + import {hType} from './YfmHeadingSpecs/utils'; -import {HeadingLevel, YfmHeadingAttr} from './const'; +import {HeadingLevel, YfmHeadingAttr, headingLevelAttr} from './const'; export {resetHeading} from '../../markdown/Heading/commands'; export const toHeading = (level: HeadingLevel): Command => - (state, dispatch) => { + (state, dispatch, view) => { const parentHeading = findParentNodeOfType(hType(state.schema))(state.selection); - if (parentHeading) { - dispatch?.( - state.tr.setNodeMarkup(parentHeading.pos, undefined, { - ...parentHeading.node.attrs, - [YfmHeadingAttr.Level]: level, - }), - ); - - return true; + if (parentHeading && parentHeading.node.attrs[headingLevelAttr] === level) { + return toParagraph(state, dispatch, view); } // const text = state.selection.$head.parent.textContent;