Make headers buttons toggle headers
This commit is contained in:
@ -82,8 +82,21 @@ export default class Editor extends Component {
|
|||||||
|
|
||||||
handleHeader = level => (
|
handleHeader = level => (
|
||||||
() => {
|
() => {
|
||||||
const command = setBlockType(schema.nodes.heading, { level });
|
const state = this.view.state;
|
||||||
command(this.view.state, this.handleAction);
|
const { $from, to, node } = state.selection;
|
||||||
|
let nodeType = schema.nodes.heading;
|
||||||
|
let attrs = { level };
|
||||||
|
let inHeader = node && node.hasMarkup(nodeType, attrs);
|
||||||
|
if (!inHeader) {
|
||||||
|
inHeader = to <= $from.end() && $from.parent.hasMarkup(nodeType, attrs);
|
||||||
|
}
|
||||||
|
if (inHeader) {
|
||||||
|
nodeType = schema.nodes.paragraph;
|
||||||
|
attrs = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const command = setBlockType(nodeType, { level });
|
||||||
|
command(state, this.handleAction);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user