From c51122ac8dfba898ecc190d765f61722ccaf7110 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Tue, 17 Sep 2024 16:39:08 +0700 Subject: [PATCH] UBERF-8145 Do not focus on editor when adding a table (#6598) Signed-off-by: Alexander Onnikov --- .../src/components/CollaborativeTextEditor.svelte | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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':