fix(searchList): speed up ctrl-k search by using SPFM (#16393)

This commit is contained in:
Jonathan Rainville 2024-09-27 12:05:23 -04:00 committed by GitHub
parent 730fcef6de
commit c09de56678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 58 deletions

View File

@ -1738,34 +1738,10 @@ Item {
sourceComponent: StatusSearchListPopup { sourceComponent: StatusSearchListPopup {
searchBoxPlaceholder: qsTr("Where do you want to go?") searchBoxPlaceholder: qsTr("Where do you want to go?")
model: rootStore.chatSearchModel model: rootStore.chatSearchModel
delegate: StatusListItem {
property var modelData
property bool isCurrentItem: true
function filterAccepts(searchText) {
const lowerCaseSearchText = searchText.toLowerCase()
return title.toLowerCase().includes(lowerCaseSearchText) || label.toLowerCase().includes(lowerCaseSearchText)
}
title: modelData ? modelData.name : ""
label: modelData? modelData.sectionName : ""
highlighted: isCurrentItem
sensor.hoverEnabled: false
statusListItemIcon {
name: modelData ? modelData.name : ""
active: true
}
asset.width: 30
asset.height: 30
asset.color: modelData ? modelData.color ? modelData.color : Utils.colorForColorId(modelData.colorId) : ""
asset.name: modelData ? modelData.icon : ""
asset.charactersLen: 2
asset.letterSize: asset._twoLettersSize
ringSettings.ringSpecModel: modelData ? modelData.colorHash : undefined
}
onAboutToShow: rootStore.rebuildChatSearchModel() onAboutToShow: rootStore.rebuildChatSearchModel()
onSelected: { onSelected: {
rootStore.setActiveSectionChat(modelData.sectionId, modelData.chatId) rootStore.setActiveSectionChat(sectionId, chatId)
close() close()
} }
} }

View File

@ -7,7 +7,9 @@ import StatusQ.Components 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1
import SortFilterProxyModel 0.2
import utils 1.0 import utils 1.0
Popup { Popup {
@ -18,19 +20,11 @@ Popup {
width: 400 width: 400
height: 300 height: 300
property alias model: listView.model required property var model
// delegate interface has to be fulfilled
property Component delegate: Item {
property var modelData
property bool isCurrentItem
function filterAccepts(searchText) {
return true
}
}
property string searchBoxPlaceholder: qsTr("Search...") property string searchBoxPlaceholder: qsTr("Search...")
signal selected(int index, var modelData) signal selected(string sectionId, string chatId)
background: Rectangle { background: Rectangle {
radius: Style.current.radius radius: Style.current.radius
@ -83,8 +77,7 @@ Popup {
return root.close() return root.close()
} }
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
return root.selected(listView.currentIndex, return listView.currentItem.selectThisItem()
listView.currentItem.myData)
} }
if (!listView.currentItem.visible) { if (!listView.currentItem.visible) {
goToNextAvailableIndex(false) goToNextAvailableIndex(false)
@ -104,26 +97,44 @@ Popup {
highlightMoveDuration: 200 highlightMoveDuration: 200
delegate: Item { model: SortFilterProxyModel {
id: delegateItem sourceModel: root.model
property var myData: typeof modelData === "undefined" ? model : modelData filters: AnyOf {
SearchFilter {
width: listView.width roleName: "sectionName"
height: visible ? delegateLoader.height : 0 searchPhrase: searchBox.text
}
Loader { SearchFilter {
id: delegateLoader roleName: "name"
searchPhrase: searchBox.text
width: parent.width
sourceComponent: root.delegate
onLoaded: {
item.modelData = delegateItem.myData
item.isCurrentItem = Qt.binding(() => delegateItem.ListView.isCurrentItem)
delegateItem.visible = Qt.binding(() => item.filterAccepts(searchBox.text))
} }
} }
}
delegate: StatusListItem {
id: listItem
function selectThisItem() {
root.selected(model.sectionId, model.chatId)
}
title: model ? model.name : ""
label: model? model.sectionName : ""
highlighted: ListView.isCurrentItem
width: ListView.view.width
sensor.hoverEnabled: false
statusListItemIcon {
name: model ? model.name : ""
active: true
}
asset.width: 30
asset.height: 30
asset.color: model ? model.color ? model.color : Utils.colorForColorId(model.colorId) : ""
asset.name: model ? model.icon : ""
asset.charactersLen: 2
asset.letterSize: asset._twoLettersSize
ringSettings.ringSpecModel: model ? model.colorHash : undefined
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
@ -131,7 +142,7 @@ Popup {
hoverEnabled: true hoverEnabled: true
onClicked: (mouse) => { onClicked: (mouse) => {
listView.currentIndex = index listView.currentIndex = index
root.selected(index, delegateItem.myData) listItem.selectThisItem()
mouse.accepted = false mouse.accepted = false
} }
onContainsMouseChanged: if (containsMouse) listView.currentIndex = index onContainsMouseChanged: if (containsMouse) listView.currentIndex = index