diff --git a/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte b/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte index feb3c7e23b..90eab040d5 100644 --- a/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte +++ b/plugins/text-editor-resources/src/components/CollaborativeTextEditor.svelte @@ -333,11 +333,14 @@ targetItem instanceof MouseEvent ? getEventPositionElement(targetItem) : getPopupPositionElement(targetItem) } - // addTableHandler opens popup so the editor loses focus - // so in the callback we need to refocus again - void addTableHandler((options: { rows?: number, cols?: number, withHeaderRow?: boolean }) => { - editor.chain().insertTable(options).focus(pos).run() - }, position) + // We need to trigger it asynchronously in order for the editor to finish its focus event + // Otherwise, it hoggs the focus from the popup and keyboard navigation doesn't work + setTimeout(() => { + // addTableHandler opens popup so the editor loses focus so in the callback we need to refocus again + void addTableHandler((options: { rows?: number, cols?: number, withHeaderRow?: boolean }) => { + editor.chain().focus(pos).insertTable(options).run() + }, position) + }, 0) break } case 'code-block':