Skip to content

Commit

Permalink
fix: heading state remains when changed to paragraph in WYSIWYG (#2103)
Browse files Browse the repository at this point in the history
* fix: heading element is not changed to paragraph when executing heading command with level 0

* chore: add test case(wysiwyg heading command)
  • Loading branch information
js87zz authored Dec 10, 2021
1 parent e70e08a commit 0b62896
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions apps/editor/src/__test__/unit/wysiwyg/wwCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ describe('wysiwyg commands', () => {

expect(wwe.getHTML()).toBe('<h6>foo</h6>');
});

it('should change heading element to paragraph with level 0', () => {
setTextToEditor('foo');

cmd.exec('selectAll');
cmd.exec('heading', { level: 0 });

expect(wwe.getHTML()).toBe('foo');
});
});

describe('hr command', () => {
Expand Down
7 changes: 5 additions & 2 deletions apps/editor/src/wysiwyg/nodes/heading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class Heading extends NodeSchema {
}

commands(): EditorCommand {
return (payload) => (state, dispatch) =>
setBlockType(state.schema.nodes.heading, payload)(state, dispatch);
return (payload) => (state, dispatch) => {
const nodeType = state.schema.nodes[payload!.level ? 'heading' : 'paragraph'];

return setBlockType(nodeType, payload)(state, dispatch);
};
}
}

0 comments on commit 0b62896

Please sign in to comment.