|
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! |
Answered by
lanwin
Nov 7, 2024
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"}]
] |
2 replies
|
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 });
} |
0 replies
Answer selected by
lanwin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone else having this problem, the following code did it.