diff --git a/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts b/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts index 015cf22420..756c2c1c36 100644 --- a/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +++ b/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts @@ -14,9 +14,9 @@ import { DefaultSuggestionItem } from "./DefaultSuggestionItem.js"; import { SuggestionMenu } from "./SuggestionMenu.js"; // Sets the editor's text cursor position to the next content editable block, -// so either a block with inline content or a table. The last block is always a -// paragraph, so this function won't try to set the cursor position past the -// last block. +// so either a block with inline content or a table. If no such block exists +// after the current one, an empty paragraph is appended to the end of the +// document and the cursor is moved to it. function setSelectionToNextContentEditableBlock< BSchema extends BlockSchema, I extends InlineContentSchema, @@ -29,6 +29,16 @@ function setSelectionToNextContentEditableBlock< while (contentType === "none") { block = editor.getTextCursorPosition().nextBlock; if (block === undefined) { + // No content editable block exists after the current one, so we append + // an empty paragraph to the end of the document and move the cursor to + // it. + const lastBlock = editor.document[editor.document.length - 1]; + const newBlock = editor.insertBlocks( + [{ type: "paragraph" }], + lastBlock, + "after", + )[0]; + editor.setTextCursorPosition(newBlock, "end"); return; } contentType = editor.schema.blockSchema[block.type].content as diff --git a/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-chromium-linux.png b/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-chromium-linux.png index 7e78e6ec92..8891baa46a 100644 Binary files a/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-chromium-linux.png and b/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-chromium-linux.png differ diff --git a/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-firefox-linux.png b/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-firefox-linux.png index bd00eddd6d..bdf0682fd7 100644 Binary files a/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-firefox-linux.png and b/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-firefox-linux.png differ diff --git a/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-webkit-linux.png b/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-webkit-linux.png index c2baa49abc..d50b0bf1ab 100644 Binary files a/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-webkit-linux.png and b/tests/src/end-to-end/ariakit/__screenshots__/ariakit.test.tsx/ariakit-image-toolbar-webkit-linux.png differ diff --git a/tests/src/end-to-end/dragdrop/dragdrop.test.tsx b/tests/src/end-to-end/dragdrop/dragdrop.test.tsx index 9a79a12fcb..2873daec38 100644 --- a/tests/src/end-to-end/dragdrop/dragdrop.test.tsx +++ b/tests/src/end-to-end/dragdrop/dragdrop.test.tsx @@ -102,7 +102,8 @@ describe("Check Block Dragging Functionality", () => { await focusOnEditor(); await executeSlashCommand("image"); await userEvent.keyboard("{Escape}"); - await userEvent.click(await waitForSelector(".bn-trailing-block")); + const paragraphs = document.querySelectorAll(PARAGRAPH_SELECTOR); + await userEvent.click(paragraphs[paragraphs.length - 1]); await insertHeading(1); await dragAndDropBlock(IMAGE_SELECTOR, H_ONE_BLOCK_SELECTOR, false); @@ -119,7 +120,8 @@ describe("Check Block Dragging Functionality", () => { await focusOnEditor(); await executeSlashCommand("image"); await userEvent.keyboard("{Escape}"); - await userEvent.click(await waitForSelector(".bn-trailing-block")); + const paragraphs = document.querySelectorAll(PARAGRAPH_SELECTOR); + await userEvent.click(paragraphs[paragraphs.length - 1]); await insertHeading(1); await dragAndDropBlock(IMAGE_SELECTOR, H_ONE_BLOCK_SELECTOR, false); diff --git a/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-chromium-linux.png b/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-chromium-linux.png index 17a9e2919e..32c5a65f99 100644 Binary files a/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-chromium-linux.png and b/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-chromium-linux.png differ diff --git a/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-firefox-linux.png b/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-firefox-linux.png index 179a8e942c..09682f8601 100644 Binary files a/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-firefox-linux.png and b/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-firefox-linux.png differ diff --git a/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-webkit-linux.png b/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-webkit-linux.png index 40a91527d2..cbed364961 100644 Binary files a/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-webkit-linux.png and b/tests/src/end-to-end/images/__screenshots__/images.test.tsx/create-image-webkit-linux.png differ diff --git a/tests/src/end-to-end/images/__snapshots__/createImage.json b/tests/src/end-to-end/images/__snapshots__/createImage.json index 5e40c74d39..b97de427ca 100644 --- a/tests/src/end-to-end/images/__snapshots__/createImage.json +++ b/tests/src/end-to-end/images/__snapshots__/createImage.json @@ -22,6 +22,22 @@ } } ] + }, + { + "type": "blockContainer", + "attrs": { + "id": "1" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + } + } + ] } ] } diff --git a/tests/src/end-to-end/images/__snapshots__/embedImage.json b/tests/src/end-to-end/images/__snapshots__/embedImage.json index a37d07751a..435926a46f 100644 --- a/tests/src/end-to-end/images/__snapshots__/embedImage.json +++ b/tests/src/end-to-end/images/__snapshots__/embedImage.json @@ -22,6 +22,22 @@ } } ] + }, + { + "type": "blockContainer", + "attrs": { + "id": "1" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + } + } + ] } ] } diff --git a/tests/src/end-to-end/images/__snapshots__/resizeImage.json b/tests/src/end-to-end/images/__snapshots__/resizeImage.json index 6c4b8deddf..c91d4d93bc 100644 --- a/tests/src/end-to-end/images/__snapshots__/resizeImage.json +++ b/tests/src/end-to-end/images/__snapshots__/resizeImage.json @@ -23,6 +23,22 @@ } } ] + }, + { + "type": "blockContainer", + "attrs": { + "id": "1" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + } + } + ] } ] } diff --git a/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImage.json b/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImage.json index 6744f59493..cb66bb0c92 100644 --- a/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImage.json +++ b/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImage.json @@ -25,6 +25,22 @@ ] } ] + }, + { + "type": "blockContainer", + "attrs": { + "id": "2" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + } + } + ] } ] } diff --git a/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImageChild.json b/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImageChild.json index 6744f59493..cb66bb0c92 100644 --- a/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImageChild.json +++ b/tests/src/end-to-end/keyboardhandlers/__snapshots__/deleteImageChild.json @@ -25,6 +25,22 @@ ] } ] + }, + { + "type": "blockContainer", + "attrs": { + "id": "2" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + } + } + ] } ] } diff --git a/tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.tsx b/tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.tsx index 6d1556628c..c33f704dd2 100644 --- a/tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.tsx +++ b/tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.tsx @@ -229,6 +229,7 @@ describe("Check Keyboard Handlers' Behaviour", () => { await executeSlashCommand("image"); await userEvent.keyboard("{Escape}"); // Close file panel + await userEvent.keyboard("{ArrowUp}"); await userEvent.keyboard("{Delete}"); await compareDocToSnapshot("deleteSelectedImage"); diff --git a/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-chromium-linux.png b/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-chromium-linux.png index 25463ea2e2..88b6f539a0 100644 Binary files a/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-chromium-linux.png and b/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-chromium-linux.png differ diff --git a/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-firefox-linux.png b/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-firefox-linux.png index fdacc22113..53cd85457d 100644 Binary files a/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-firefox-linux.png and b/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-firefox-linux.png differ diff --git a/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-webkit-linux.png b/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-webkit-linux.png index 86782993f2..d66e677cec 100644 Binary files a/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-webkit-linux.png and b/tests/src/end-to-end/shadcn/__screenshots__/shadcn.test.tsx/shadcn-image-toolbar-webkit-linux.png differ diff --git a/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-chromium-linux.png b/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-chromium-linux.png index feb4202914..41c579ae20 100644 Binary files a/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-chromium-linux.png and b/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-chromium-linux.png differ diff --git a/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-firefox-linux.png b/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-firefox-linux.png index 7ea0d22ea1..8d8dc56fa7 100644 Binary files a/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-firefox-linux.png and b/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-firefox-linux.png differ diff --git a/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-webkit-linux.png b/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-webkit-linux.png index 94a53d8dc6..bde04467ae 100644 Binary files a/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-webkit-linux.png and b/tests/src/end-to-end/theming/__screenshots__/theming.test.tsx/dark-image-toolbar-webkit-linux.png differ diff --git a/tests/src/utils/copypaste.ts b/tests/src/utils/copypaste.ts index 05fc79752a..472df07cf6 100644 --- a/tests/src/utils/copypaste.ts +++ b/tests/src/utils/copypaste.ts @@ -1,5 +1,4 @@ import { MOD, userEvent } from "./context.js"; -import { waitForSelector } from "./editor.js"; export function selectAll() { return userEvent.keyboard(`{${MOD}>}a{/${MOD}}`); @@ -9,7 +8,18 @@ export async function copyPaste() { await userEvent.keyboard(`{${MOD}>}c{/${MOD}}`); // Exit out of any menus/toolbars which may block the trailing block. await userEvent.keyboard("{Escape}"); - await userEvent.click(await waitForSelector(".bn-trailing-block")); + // The trailing block isn't always present (e.g. when the editor's last block + // can't have one), so fall back to the last paragraph. + const trailingBlock = + document.querySelector(".bn-trailing-block"); + if (trailingBlock) { + await userEvent.click(trailingBlock); + } else { + const paragraphs = document.querySelectorAll( + '[data-content-type="paragraph"]', + ); + await userEvent.click(paragraphs[paragraphs.length - 1]); + } await userEvent.keyboard(`{${MOD}>}v{/${MOD}}`); }