Skip to content

Commit

Permalink
Editor: add insertNode util
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Apr 6, 2024
1 parent f32049f commit 1804973
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 1 addition & 4 deletions panel/src/components/Forms/Writer/Nodes/HardBreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ export default class HardBreak extends Node {
}

createHardBreak(utils, type) {
return utils.chainCommands(utils.exitCode, (state, dispatch) => {
dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
return true;
});
return utils.chainCommands(utils.exitCode, utils.insertNode(type));
}

get defaults() {
Expand Down
5 changes: 2 additions & 3 deletions panel/src/components/Forms/Writer/Nodes/HorizontalRule.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Node from "../Node";

export default class HorizontalRule extends Node {
commands({ type }) {
return () => (state, dispatch) =>
dispatch(state.tr.replaceSelectionWith(type.create()));
commands({ type, utils }) {
return () => utils.insertNode(type);
}

inputRules({ type, utils }) {
Expand Down
2 changes: 2 additions & 0 deletions panel/src/components/Forms/Writer/Utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
// custom
import getMarkAttrs from "./getMarkAttrs";
import getNodeAttrs from "./getNodeAttrs";
import insertNode from "./insertNode";
import markInputRule from "./markInputRule";
import markIsActive from "./markIsActive";
import markPasteRule from "./markPasteRule";
Expand Down Expand Up @@ -61,6 +62,7 @@ export default {
// custom
getMarkAttrs,
getNodeAttrs,
insertNode,
markInputRule,
markIsActive,
markPasteRule,
Expand Down
5 changes: 5 additions & 0 deletions panel/src/components/Forms/Writer/Utils/insertNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function insertNode(type) {
return (state, dispatch) => {
dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
};
}

0 comments on commit 1804973

Please sign in to comment.