From 5a183a707cb10a3d65a8050580749d2a4c50df5c Mon Sep 17 00:00:00 2001 From: "Xsyl.way" <98275209+Xcylway@users.noreply.github.com> Date: Mon, 19 Oct 2026 15:17:34 +0800 Subject: [PATCH] fix(sidebar): restore keyboard focus after dialogs --- apps/desktop/src/App.vue | 12 ++-- .../src/components/layout/AppSidebar.vue | 6 +- .../src/components/sidebar/ConnectionTree.vue | 62 ++++++++++++++++--- .../src/components/sidebar/TreeItem.vue | 32 ++++++++-- .../TreeItem.connectionRename.spec.ts | 33 ++++++++++ 5 files changed, 129 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index bf49ba1adc..35051a1939 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -3185,13 +3185,17 @@ async function openPendingPluginInstallLinks() { } } -function setConnectionDialogOpen(value: boolean) { +function setConnectionDialogOpen(value: boolean, options?: { restoreFocus?: boolean }) { showConnectionDialog.value = value; if (!value) { connectionDialogPrefill.value = null; connectionDialogUpdate.value = null; connectionPluginProvider.value = null; connectionDialogInitialTab.value = undefined; + // Handlers that immediately open another surface (driver store page, + // settings, or a reopened connection dialog) opt out: the delayed tree + // refocus would steal focus back from the new surface's autofocus. + if (options?.restoreFocus !== false) void appSidebarRef.value?.focusSelectedNode(); } } @@ -5687,15 +5691,15 @@ onUnmounted(() => { ) " @open-driver-store=" - setConnectionDialogOpen(false); + setConnectionDialogOpen(false, { restoreFocus: false }); openDriverStorePage($event); " @open-tunnel-profile-settings=" - setConnectionDialogOpen(false); + setConnectionDialogOpen(false, { restoreFocus: false }); openSettings('tunnels'); " @open-connection-settings=" - setConnectionDialogOpen(false); + setConnectionDialogOpen(false, { restoreFocus: false }); openConnectionSettings($event, 'advanced'); " @open-lineage-target="openLineageTarget" diff --git a/apps/desktop/src/components/layout/AppSidebar.vue b/apps/desktop/src/components/layout/AppSidebar.vue index bef4bf2de2..458d9fe07a 100644 --- a/apps/desktop/src/components/layout/AppSidebar.vue +++ b/apps/desktop/src/components/layout/AppSidebar.vue @@ -220,7 +220,11 @@ function openTableStructureForSelection(): boolean { return connectionTreeRef.value?.openTableStructureForSelection?.() ?? false; } -defineExpose({ focusSearch, locateTabInSidebar, disconnectAllActiveConnections, openTableStructureForSelection }); +async function focusSelectedNode() { + await connectionTreeRef.value?.focusSelectedNode?.(); +} + +defineExpose({ focusSearch, locateTabInSidebar, disconnectAllActiveConnections, focusSelectedNode, openTableStructureForSelection });