From 0cefc235d59bdd1d52460d971cd6a9d18f229d52 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Wed, 10 Apr 2024 13:37:52 +0800 Subject: [PATCH] feat: press enter to open the 1st result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 行为调整,当正在搜索时,回车将直接启动结果中被选中的结果(即第一个 结果),而不再是将焦点移到搜索区域。注意,当前实现仍与4/9讨论的预期 行为不同,预期是希望搜索过程中也始终显示选中项,即搜索结果区域无焦 点时,选中项也有一个近似于hover效果的指示效果的。 未在搜索时的行为不变(即,如果焦点在搜索框但没输入任何关键词就按下 回车,此时会将焦点切换到应用区域)。 Log: --- qml/FullscreenFrame.qml | 7 +++---- qml/GridViewContainer.qml | 2 ++ qml/windowed/GridViewContainer.qml | 1 + qml/windowed/SearchResultView.qml | 4 ++++ qml/windowed/WindowedFrame.qml | 8 +++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/qml/FullscreenFrame.qml b/qml/FullscreenFrame.qml index 219af1f7..c265a1e0 100644 --- a/qml/FullscreenFrame.qml +++ b/qml/FullscreenFrame.qml @@ -498,15 +498,14 @@ Control { Keys.onReturnPressed: { if (searchEdit.text === "") { pages.focus = true - // TODO: ensure the first one is actually selected? } else { - searchResultGridViewContainer.focus = true - // TODO: ensure the first one is actually selected? + searchResultGridViewContainer.currentItem?.onItemClicked() } } onTextChanged: { -// console.log(text) SearchFilterProxyModel.setFilterRegularExpression(text.trim()) + // this can help indirectly reset the currentIndex of the view that the model is attached to + SearchFilterProxyModel.invalidate() } } } diff --git a/qml/GridViewContainer.qml b/qml/GridViewContainer.qml index 2d5942da..66df02d8 100644 --- a/qml/GridViewContainer.qml +++ b/qml/GridViewContainer.qml @@ -30,6 +30,8 @@ FocusScope { property alias cellHeight: item.cellHeight property alias cellWidth: item.cellWidth + readonly property alias currentIndex: gridView.currentIndex + readonly property alias currentItem: gridView.currentItem readonly property alias gridViewWidth: gridView.width function setPreviousPageSwitch(state) { diff --git a/qml/windowed/GridViewContainer.qml b/qml/windowed/GridViewContainer.qml index f5833513..dfa020ef 100644 --- a/qml/windowed/GridViewContainer.qml +++ b/qml/windowed/GridViewContainer.qml @@ -30,6 +30,7 @@ FocusScope { property real cellHeight: 72 property real cellWidth: 80 + readonly property alias currentItem: gridView.currentItem readonly property alias gridViewWidth: gridView.width property alias highlight: gridView.highlight diff --git a/qml/windowed/SearchResultView.qml b/qml/windowed/SearchResultView.qml index 8028ef38..b91996e1 100644 --- a/qml/windowed/SearchResultView.qml +++ b/qml/windowed/SearchResultView.qml @@ -18,6 +18,10 @@ Control { searchResultViewContainer.focus = true } + function launchCurrentItem() { + searchResultViewContainer.currentItem?.onItemClicked() + } + function positionViewAtBeginning() { searchResultViewContainer.positionViewAtBeginning() } diff --git a/qml/windowed/WindowedFrame.qml b/qml/windowed/WindowedFrame.qml index 1e50ee65..b4dc74ba 100644 --- a/qml/windowed/WindowedFrame.qml +++ b/qml/windowed/WindowedFrame.qml @@ -152,9 +152,15 @@ Item { switch (event.key) { case Qt.Key_Up: case Qt.Key_Down: + appGridLoader.item.forceActiveFocus() + return; case Qt.Key_Enter: case Qt.Key_Return: - appGridLoader.item.forceActiveFocus() + if (bottomBar.searchEdit.text !== "") { + appGridLoader.item.launchCurrentItem() + } else { + appGridLoader.item.forceActiveFocus() + } } } }