Skip to content

Commit 7243511

Browse files
committed
fix(ui): read the caret before Mod+/ checks for a block menu
A Mod+/ right after a click could see the caret from before the click, because the model reads a click's caret on selectionchange. Mod+/ now reads the browser selection first. The callout API test waits for the caret the same way, which made CI fail on a slower runner. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M15YF742ggoWPyh9ZzZ1Jm
1 parent 8793b51 commit 7243511

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎e2e/callout.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ test('the API reads and changes callouts', async ({ page }) => {
113113
const e = (window as any).editor;
114114
return [e.isActive('blockquote'), e.getAttributes('blockquote'), e.isActive('blockquote', { callout: 'warning' })];
115115
});
116-
expect(await api()).toEqual([true, { callout: 'warning' }, true]);
116+
// The model reads the click's caret on selectionchange, which can come after the click returns.
117+
await expect.poll(api).toEqual([true, { callout: 'warning' }, true]);
117118
await page.evaluate(() => (window as any).editor.commands.setCallout({ type: 'important' }));
118119
expect(await blocks(page)).toContain('important:Careful.');
119120
await page.evaluate(() => (window as any).editor.commands.setCallout({ type: null }));

‎packages/editor/src/editor.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,8 @@ export class Editor {
20392039
}
20402040

20412041
if (mod && !e.altKey) {
2042+
// Read the caret first: a click just before the key may not have reached selectionchange yet.
2043+
if (e.key === '/' && !e.shiftKey) this.refreshSelection();
20422044
if (e.key === '/' && !e.shiftKey && this.hasBlockMenu(this.state.selection.focus.blockId)) {
20432045
return handled(() => this.openBlockMenu(this.state.selection.focus.blockId));
20442046
}

0 commit comments

Comments
 (0)