Skip to content

Commit

Permalink
feat: press enter to open the 1st result
Browse files Browse the repository at this point in the history
行为调整,当正在搜索时,回车将直接启动结果中被选中的结果(即第一个
结果),而不再是将焦点移到搜索区域。注意,当前实现仍与4/9讨论的预期
行为不同,预期是希望搜索过程中也始终显示选中项,即搜索结果区域无焦
点时,选中项也有一个近似于hover效果的指示效果的。

未在搜索时的行为不变(即,如果焦点在搜索框但没输入任何关键词就按下
回车,此时会将焦点切换到应用区域)。

Log:
  • Loading branch information
BLumia authored and deepin-bot[bot] committed Apr 10, 2024
1 parent cdd8b2d commit 0cefc23
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
7 changes: 3 additions & 4 deletions qml/FullscreenFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions qml/GridViewContainer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions qml/windowed/GridViewContainer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions qml/windowed/SearchResultView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Control {
searchResultViewContainer.focus = true
}

function launchCurrentItem() {
searchResultViewContainer.currentItem?.onItemClicked()
}

function positionViewAtBeginning() {
searchResultViewContainer.positionViewAtBeginning()
}
Expand Down
8 changes: 7 additions & 1 deletion qml/windowed/WindowedFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down

0 comments on commit 0cefc23

Please sign in to comment.