@@ -47,16 +47,21 @@ function deleteSingleSelectedNode(editor: LexicalEditor) {
|
47 | 47 | * Insert a new empty node before/after the selection if the selection contains a single
|
48 | 48 | * selected node (like image, media etc...).
|
49 | 49 | */
|
50 |
| -function insertAfterSingleSelectedNode(editor: LexicalEditor, event: KeyboardEvent|null): boolean { |
| 50 | +function insertAdjacentToSingleSelectedNode(editor: LexicalEditor, event: KeyboardEvent|null): boolean { |
51 | 51 | const selectionNodes = getLastSelection(editor)?.getNodes() || [];
|
52 | 52 | if (isSingleSelectedNode(selectionNodes)) {
|
53 | 53 | const node = selectionNodes[0];
|
54 | 54 | const nearestBlock = $getNearestNodeBlockParent(node) || node;
|
| 55 | +const insertBefore = event?.shiftKey === true; |
55 | 56 | if (nearestBlock) {
|
56 | 57 | requestAnimationFrame(() => {
|
57 | 58 | editor.update(() => {
|
58 | 59 | const newParagraph = $createParagraphNode();
|
59 |
| -nearestBlock.insertAfter(newParagraph); |
| 60 | +if (insertBefore) { |
| 61 | +nearestBlock.insertBefore(newParagraph); |
| 62 | +} else { |
| 63 | +nearestBlock.insertAfter(newParagraph); |
| 64 | +} |
60 | 65 | newParagraph.select();
|
61 | 66 | });
|
62 | 67 | });
|
@@ -75,22 +80,14 @@ function focusAdjacentOrInsertForSingleSelectNode(editor: LexicalEditor, event:
|
75 | 80 | }
|
76 | 81 |
|
77 | 82 | event?.preventDefault();
|
78 |
| - |
79 | 83 | const node = selectionNodes[0];
|
80 |
| -const nearestBlock = $getNearestNodeBlockParent(node) || node; |
81 |
| -let target = after ? nearestBlock.getNextSibling() : nearestBlock.getPreviousSibling(); |
82 | 84 |
|
83 | 85 | editor.update(() => {
|
84 |
| -if (!target) { |
85 |
| -target = $createParagraphNode(); |
86 |
| -if (after) { |
87 |
| -nearestBlock.insertAfter(target) |
88 |
| -} else { |
89 |
| -nearestBlock.insertBefore(target); |
90 |
| -} |
| 86 | +if (after) { |
| 87 | +node.selectNext(); |
| 88 | +} else { |
| 89 | +node.selectPrevious(); |
91 | 90 | }
|
92 |
| - |
93 |
| -target.selectStart(); |
94 | 91 | });
|
95 | 92 |
|
96 | 93 | return true;
|
@@ -220,7 +217,7 @@ export function registerKeyboardHandling(context: EditorUiContext): () => void {
|
220 | 217 | }, COMMAND_PRIORITY_LOW);
|
221 | 218 |
|
222 | 219 | const unregisterEnter = context.editor.registerCommand(KEY_ENTER_COMMAND, (event): boolean => {
|
223 |
| -return insertAfterSingleSelectedNode(context.editor, event) |
| 220 | +return insertAdjacentToSingleSelectedNode(context.editor, event) |
224 | 221 | || moveAfterDetailsOnEmptyLine(context.editor, event);
|
225 | 222 | }, COMMAND_PRIORITY_LOW);
|
226 | 223 |
|
|
0 commit comments