-
|
When I press This is what I think should work - // Shift
if (event.shiftKey) {
// Shift + Enter
if (event.key === 'Enter') {
event.preventDefault();
event.stopPropagation();
// `point` refers to the top-most level block.
const point = editor.selection.anchor.path.at(0);
if (point) {
// `next` should be the next top-most 'block' location.
const next = Editor.after(editor, [point]);
if (next) {
Transforms.insertNodes(
editor,
{
type: 'paragraph',
children: [{ text: '' }]
},
{ at: next }
);
// Put cursor in the newly created block.
Transforms.select(editor, next);
Transforms.collapse(editor);
return;
}
}
}
}This does escape current block but doesn't always create a new node. Sometimes it jump to the next block. Not sure what I could be doing wrong. Any help is greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Answered by
TheSpyder
Aug 31, 2022
Replies: 1 comment 1 reply
-
|
Try It could also be normalisation changing what you inserted, although that seems unlikely. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cometw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try
Path.next()instead ofEditor.after(). That might better guarantee you're inserting where you intend to.It could also be normalisation changing what you inserted, although that seems unlikely.