Skip to content

Commit

Permalink
feat: heading button that resets heading back to paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
smsochneg committed Feb 15, 2024
1 parent 03a1ad2 commit b8648a7
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/extensions/yfm/YfmHeading/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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;
return toParagraph(state, dispatch, view);
}

// const text = state.selection.$head.parent.textContent;
Expand Down

0 comments on commit b8648a7

Please sign in to comment.