diff --git a/packages/core/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts b/packages/core/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts index 19ea7bc77a..64847e51e0 100644 --- a/packages/core/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +++ b/packages/core/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts @@ -379,6 +379,8 @@ export class BlockMenuView { .BNUpdateBlock(newBlockContentPos, { type: "paragraph", props: {} }) .setTextSelection(newBlockContentPos) .run(); + } else { + this.editor.commands.setTextSelection(endPos); } // Focuses and activates the suggestion menu. diff --git a/tests/end-to-end/draghandle/draghandle.test.ts b/tests/end-to-end/draghandle/draghandle.test.ts index f9ce310df7..07c7c067e9 100644 --- a/tests/end-to-end/draghandle/draghandle.test.ts +++ b/tests/end-to-end/draghandle/draghandle.test.ts @@ -131,6 +131,14 @@ test.describe("Check Draghandle functionality", () => { await page.waitForSelector(DRAG_HANDLE_ADD_SELECTOR, { state: "detached" }); }); + test("Click add button for non-selected empty block", async () => { + await executeSlashCommand(page, "h1"); + await page.keyboard.type("Heading 1"); + await hoverAndAddBlockFromDragHandle(page, PARAGRAPH_SELECTOR, "h1"); + + await compareDocToSnapshot(page, "addnonselectedemptyblock"); + }); + test("Clicking delete button should delete block", async () => { await executeSlashCommand(page, "h1"); await page.keyboard.type("Hover over this text"); diff --git a/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-chromium-linux.json b/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-chromium-linux.json new file mode 100644 index 0000000000..23d734e9d7 --- /dev/null +++ b/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-chromium-linux.json @@ -0,0 +1,66 @@ +{ + "type": "doc", + "content": [ + { + "type": "blockGroup", + "content": [ + { + "type": "blockContainer", + "attrs": { + "id": 0, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "heading", + "attrs": { + "textAlignment": "left", + "level": "1" + }, + "content": [ + { + "type": "text", + "text": "Heading 1" + } + ] + } + ] + }, + { + "type": "blockContainer", + "attrs": { + "id": 1, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "heading", + "attrs": { + "textAlignment": "left", + "level": "1" + } + } + ] + }, + { + "type": "blockContainer", + "attrs": { + "id": 2, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "textAlignment": "left" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-firefox-linux.json b/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-firefox-linux.json new file mode 100644 index 0000000000..23d734e9d7 --- /dev/null +++ b/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-firefox-linux.json @@ -0,0 +1,66 @@ +{ + "type": "doc", + "content": [ + { + "type": "blockGroup", + "content": [ + { + "type": "blockContainer", + "attrs": { + "id": 0, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "heading", + "attrs": { + "textAlignment": "left", + "level": "1" + }, + "content": [ + { + "type": "text", + "text": "Heading 1" + } + ] + } + ] + }, + { + "type": "blockContainer", + "attrs": { + "id": 1, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "heading", + "attrs": { + "textAlignment": "left", + "level": "1" + } + } + ] + }, + { + "type": "blockContainer", + "attrs": { + "id": 2, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "textAlignment": "left" + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-webkit-linux.json b/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-webkit-linux.json new file mode 100644 index 0000000000..23d734e9d7 --- /dev/null +++ b/tests/end-to-end/draghandle/draghandle.test.ts-snapshots/addnonselectedemptyblock-webkit-linux.json @@ -0,0 +1,66 @@ +{ + "type": "doc", + "content": [ + { + "type": "blockGroup", + "content": [ + { + "type": "blockContainer", + "attrs": { + "id": 0, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "heading", + "attrs": { + "textAlignment": "left", + "level": "1" + }, + "content": [ + { + "type": "text", + "text": "Heading 1" + } + ] + } + ] + }, + { + "type": "blockContainer", + "attrs": { + "id": 1, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "heading", + "attrs": { + "textAlignment": "left", + "level": "1" + } + } + ] + }, + { + "type": "blockContainer", + "attrs": { + "id": 2, + "textColor": "default", + "backgroundColor": "default" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "textAlignment": "left" + } + } + ] + } + ] + } + ] +} \ No newline at end of file