-
-
Notifications
You must be signed in to change notification settings - Fork 741
fix: Slash menu item selection behaviour (BLO-1222) #2838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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<HTMLElement>(".bn-trailing-block"); | ||||||||||||||||||||||||||||
| if (trailingBlock) { | ||||||||||||||||||||||||||||
| await userEvent.click(trailingBlock); | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| const paragraphs = document.querySelectorAll<HTMLElement>( | ||||||||||||||||||||||||||||
| '[data-content-type="paragraph"]', | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| await userEvent.click(paragraphs[paragraphs.length - 1]); | ||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard the paragraph fallback before clicking. If Suggested fix } else {
const paragraphs = document.querySelectorAll<HTMLElement>(
'[data-content-type="paragraph"]',
);
+ if (paragraphs.length === 0) {
+ throw new Error(
+ "copyPaste: no trailing block or paragraph available to focus before paste.",
+ );
+ }
await userEvent.click(paragraphs[paragraphs.length - 1]);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| await userEvent.keyboard(`{${MOD}>}v{/${MOD}}`); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hard-coding
"paragraph"in a schema-generic cursor fallback.Line 37 always inserts
{ type: "paragraph" }, but this helper is reached through exportedinsertOrUpdateBlockForSlashMenu. In custom schemas withoutparagraph, this path will fail at runtime when insertion reaches document end. Pick an available inline-content type fromeditor.schema.blockSchema(or fail with a clear schema error) instead of assumingparagraph.Proposed direction
🤖 Prompt for AI Agents