-
Hi, I have the following case and can not get a proper solution. Maybe someone can get me a hint. Initial my editor has the following state.
Now the users select
Now the doc looks like this:
My problem is that I now have a empty line above and below the h4. This is cause the \n arent getting removed. Whats the best why to ensure that the newlines getting handled correctly? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You shouldn't use any \n markers; the initial value should be [
{type:"p",children:[{text:"test1"}],
{type:"p",children:[{text:"test2"}],
{type:"p",children:[{text:"test3"}]
] |
Beta Was this translation helpful? Give feedback.
-
For anyone else having this problem, the following code did it. Transforms.setNodes(editor, { type: "h4" }, { mode: 'lowest', voids: false, split: true });
const after = Editor.after(editor, editor.selection);
if (after) {
const [nodeAfter, pathAfter] = Editor.node(editor, after);
if (Text.isText(nodeAfter) && nodeAfter.text.startsWith('\n'))
Transforms.delete(editor, { at: { path: pathAfter, offset: 0 }, distance: 1 });
}
const before = Editor.before(editor, editor.selection);
if (before) {
const [nodeBefore, pathBefore] = Editor.node(editor, before);
if (Text.isText(nodeBefore) && nodeBefore.text.endsWith('\n'))
Transforms.delete(editor, { at: { path: pathBefore, offset: nodeBefore.text.length - 1 }, distance: 1 });
} |
Beta Was this translation helpful? Give feedback.
For anyone else having this problem, the following code did it.