From 0e163f6ee673a09995e308a341d2333b1c3bab9b Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 14 Aug 2026 14:27:37 +0200 Subject: [PATCH] gui: fix focus stealing from dialogs during session tree rebuild buildSessionTree() and updateSessionTree() now save/restore Window.activeFocusItem instead of only promptInput.activeFocus. This prevents sessionTreeModel.clear() from pulling focus out of open modal dialogs (NewSessionDialog, NewAgentDialog). Also add forceActiveFocus() on dialog open so the first field is immediately focused. --- gui/NewAgentDialog.qml | 5 ++++- gui/NewSessionDialog.qml | 1 + gui/main.qml | 14 ++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gui/NewAgentDialog.qml b/gui/NewAgentDialog.qml index ca9880d..9e12fcc 100644 --- a/gui/NewAgentDialog.qml +++ b/gui/NewAgentDialog.qml @@ -162,5 +162,8 @@ Dialog { } } - onOpened: errorLabel.text = "" + onOpened: { + errorLabel.text = "" + dirField.forceActiveFocus() + } } diff --git a/gui/NewSessionDialog.qml b/gui/NewSessionDialog.qml index 4cdd374..a61fba6 100644 --- a/gui/NewSessionDialog.qml +++ b/gui/NewSessionDialog.qml @@ -75,5 +75,6 @@ Dialog { errorLabel.text = "" nameField.text = "" remoteField.text = "" + nameField.forceActiveFocus() } } diff --git a/gui/main.qml b/gui/main.qml index fd1261f..118c12d 100644 --- a/gui/main.qml +++ b/gui/main.qml @@ -102,7 +102,7 @@ ApplicationWindow { function buildSessionTree() { // Full rebuild - used on initial load - var hadFocus = promptInput.activeFocus + var focusItem = root.activeFocusItem sessionTreeModel.clear() modelCache = {} var sessions = ollie.sessions @@ -139,8 +139,9 @@ ApplicationWindow { appendSessionToModel(sess) } - if (hadFocus) - promptInput.forceActiveFocus() + // Restore focus to whatever had it (handles dialogs, not just promptInput) + if (focusItem && focusItem.visible) + focusItem.forceActiveFocus() } // Compute connection color from session data (avoids C++ call) @@ -197,7 +198,7 @@ ApplicationWindow { function updateSessionTree() { // Incremental update - diff old vs new - var hadFocus = promptInput.activeFocus + var focusItem = root.activeFocusItem var sessions = ollie.sessions // Build lookup of new sessions @@ -232,8 +233,9 @@ ApplicationWindow { } } - if (hadFocus) - promptInput.forceActiveFocus() + // Restore focus to whatever had it (handles dialogs, not just promptInput) + if (focusItem && focusItem.visible) + focusItem.forceActiveFocus() } function findSessionIndex(sessionId) {