diff --git a/Modules/AppLauncher.qml b/Modules/AppLauncher.qml index a66d6813..ae09de39 100644 --- a/Modules/AppLauncher.qml +++ b/Modules/AppLauncher.qml @@ -149,9 +149,6 @@ PanelWindow { searchField.enabled = true; searchDebounceTimer.stop(); // Stop any pending search updateFilteredModel(); - Qt.callLater(function() { - searchField.forceActiveFocus(); - }); } function hide() { @@ -461,6 +458,17 @@ PanelWindow { onTextEdited: { searchDebounceTimer.restart(); } + + Connections { + target: launcher + function onVisibleChanged() { + if (launcher.visible) { + searchField.forceActiveFocus(); + } else { + searchField.clearFocus(); + } + } + } Keys.onPressed: function(event) { if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && filteredModel.count && text.length > 0) { // Launch first app when typing in search field diff --git a/Modules/ClipboardHistory.qml b/Modules/ClipboardHistory.qml index e32479ea..e72f2de7 100644 --- a/Modules/ClipboardHistory.qml +++ b/Modules/ClipboardHistory.qml @@ -15,7 +15,6 @@ DankModal { property var clipboardEntries: [] property string searchText: "" - property bool shouldFocusSearch: false function updateFilteredModel() { filteredClipboardModel.clear(); @@ -118,13 +117,6 @@ DankModal { height: 550 keyboardFocus: "ondemand" - onVisibleChanged: { - if (visible) { - refreshClipboard(); - shouldFocusSearch = true; - } - } - onBackgroundClicked: { hide(); } @@ -198,14 +190,14 @@ DankModal { clipboardHistory.searchText = text; updateFilteredModel(); } - + Connections { target: clipboardHistory function onOpened() { - if (shouldFocusSearch) { - searchField.forceActiveFocus() - shouldFocusSearch = false - } + searchField.forceActiveFocus(); + } + function onDialogClosed() { + searchField.clearFocus(); } } } diff --git a/Modules/SpotlightLauncher.qml b/Modules/SpotlightLauncher.qml index efc2a8c2..67de9b58 100644 --- a/Modules/SpotlightLauncher.qml +++ b/Modules/SpotlightLauncher.qml @@ -53,8 +53,6 @@ DankModal { } property string searchQuery: "" - property bool shouldFocusSearch: false - function updateFilteredApps() { filteredApps = []; selectedIndex = 0; @@ -216,10 +214,6 @@ DankModal { } } - onOpened: { - shouldFocusSearch = true; - } - onBackgroundClicked: { spotlightOpen = false; } @@ -420,7 +414,6 @@ DankModal { showClearButton: true textColor: Theme.surfaceText font.pixelSize: Theme.fontSizeLarge - focus: false enabled: spotlightOpen placeholderText: "Search applications..." text: searchQuery @@ -428,15 +421,14 @@ DankModal { searchQuery = text; searchDebounceTimer.restart(); } - + Connections { target: spotlightLauncher function onOpened() { - if (shouldFocusSearch) { - searchField.forceActiveFocus() - searchField.selectAll() - shouldFocusSearch = false - } + searchField.forceActiveFocus(); + } + function onDialogClosed() { + searchField.clearFocus(); } } diff --git a/Modules/WifiPasswordDialog.qml b/Modules/WifiPasswordDialog.qml index 9e214682..531bc4c3 100644 --- a/Modules/WifiPasswordDialog.qml +++ b/Modules/WifiPasswordDialog.qml @@ -16,10 +16,6 @@ DankModal { height: 230 keyboardFocus: "ondemand" - onOpened: { - passwordInput.forceActiveFocus() - } - onVisibleChanged: { if (!visible) { wifiPasswordInput = ""; @@ -100,6 +96,16 @@ DankModal { onTextEdited: { wifiPasswordInput = text; } + + Connections { + target: root + function onOpened() { + passwordInput.forceActiveFocus(); + } + function onDialogClosed() { + passwordInput.clearFocus(); + } + } onAccepted: { WifiService.connectToWifiWithPassword(wifiPasswordSSID, passwordInput.text); wifiPasswordDialogVisible = false; diff --git a/Widgets/DankModal.qml b/Widgets/DankModal.qml index 8d831f59..5be67189 100644 --- a/Widgets/DankModal.qml +++ b/Widgets/DankModal.qml @@ -199,11 +199,14 @@ PanelWindow { // Keyboard handling FocusScope { + id: focusScope anchors.fill: parent - focus: visible && root.closeOnEscapeKey - Keys.onEscapePressed: { + visible: root.visible // Only active when the modal is visible + + Keys.onEscapePressed: (event) => { if (root.closeOnEscapeKey) { - visible = false + root.visible = false; + event.accepted = true; } } } diff --git a/Widgets/DankTextField.qml b/Widgets/DankTextField.qml index 45d2516e..91933516 100644 --- a/Widgets/DankTextField.qml +++ b/Widgets/DankTextField.qml @@ -83,6 +83,10 @@ Rectangle { textInput.cut(); } + function clearFocus() { + textInput.focus = false; + } + // Default styling width: 200 height: 48