From 0a66394500c991836b6e007ef1a69067ad1eb66b Mon Sep 17 00:00:00 2001 From: zsien Date: Wed, 29 May 2024 13:38:33 +0800 Subject: [PATCH] fix: the numeric keypad cannot input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 Keys.forwardTo 代替判断 event.text Issues: linuxdeepin/developer-center#8495 --- qml/FullscreenFrame.qml | 11 +++-------- qml/windowed/BottomBar.qml | 1 + qml/windowed/WindowedFrame.qml | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/qml/FullscreenFrame.qml b/qml/FullscreenFrame.qml index 00e9f447..5b75f992 100644 --- a/qml/FullscreenFrame.qml +++ b/qml/FullscreenFrame.qml @@ -545,6 +545,7 @@ Control { } } onTextChanged: { + searchEdit.focus = true SearchFilterProxyModel.setFilterRegularExpression(text.trim()) // reset highlighted item if (searchResultGridViewContainer.visible) { @@ -561,15 +562,9 @@ Control { cs: searchResultGridViewContainer.cellHeight } + Keys.forwardTo: [searchEdit] Keys.onPressed: { - if (searchEdit.focus === false && ((event.modifiers === Qt.NoModifier || event.modifiers === Qt.ShiftModifier || event.modifiers === Qt.KeypadModifier) && event.text && !"\t\r\0 ".includes(event.text))) { - searchEdit.focus = true - if (searchEdit.text) { - searchEdit.text += event.text - } else { - searchEdit.text = event.text - } - } else if (baseLayer.focus === true) { + if (baseLayer.focus === true) { // the SearchEdit will catch the key event first, and events that it won't accept will then got here switch (event.key) { case Qt.Key_Up: diff --git a/qml/windowed/BottomBar.qml b/qml/windowed/BottomBar.qml index b23fbc97..5831c619 100644 --- a/qml/windowed/BottomBar.qml +++ b/qml/windowed/BottomBar.qml @@ -59,6 +59,7 @@ Control { onTextChanged: { console.log(text) + searchEdit.focus = true SearchFilterProxyModel.setFilterRegularExpression(text.trim()) SearchFilterProxyModel.invalidate() } diff --git a/qml/windowed/WindowedFrame.qml b/qml/windowed/WindowedFrame.qml index 28e53999..102d44bf 100644 --- a/qml/windowed/WindowedFrame.qml +++ b/qml/windowed/WindowedFrame.qml @@ -181,11 +181,9 @@ Item { } } + Keys.forwardTo: [bottomBar.searchEdit] Keys.onPressed: function (event) { - if (bottomBar.searchEdit.focus === false && !bottomBar.searchEdit.text && ((event.modifiers === Qt.NoModifier || event.modifiers === Qt.ShiftModifier || event.modifiers === Qt.KeypadModifier) && event.text && !"\t\r\0 ".includes(event.text))) { - bottomBar.searchEdit.focus = true - bottomBar.searchEdit.text = event.text - } else if (bottomBar.searchEdit.focus === true || baseLayer.focus === true) { + if (bottomBar.searchEdit.focus === true || baseLayer.focus === true) { // the SearchEdit will catch the key event first, and events that it won't accept will then got here switch (event.key) { case Qt.Key_Up: