From 631e2bc1076daacdf8fbb0aee069a8a0d787b553 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 14 May 2020 20:23:21 -0400 Subject: [PATCH] Highlight index 1 when filtering rooms --- TODO.md | 2 -- src/gui/MainPane/RoomList.qml | 36 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/TODO.md b/TODO.md index e08131a4..ed3bdfd4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,5 @@ # TODO -- better initial highlight position when filtering - - fix python getting stuck when loading large room - fix accounts in room list not getting their profile updated if mirage starts with a filter diff --git a/src/gui/MainPane/RoomList.qml b/src/gui/MainPane/RoomList.qml index acfaba1b..b80d3192 100644 --- a/src/gui/MainPane/RoomList.qml +++ b/src/gui/MainPane/RoomList.qml @@ -46,23 +46,31 @@ HListView { } onFilterChanged: { - py.callCoro("set_substring_filter", ["all_rooms", filter]) + py.callCoro("set_substring_filter", ["all_rooms", filter], () => { + if (filter) { + currentIndex = 1 // highlight the first matching room + return + } - const item = model.get(currentIndex) + const item = model.get(currentIndex) - if ( - ! filter && - item && (( - currentShouldBeAccount && - wantedUserId !== item.id - ) || ( - currentShouldBeRoom && ( - wantedUserId !== item.for_account || - wantedRoomId !== item.id + if ( + ! filter && + item && ( + currentIndex === 1 || // required, related to the if above + ( + currentShouldBeAccount && + wantedUserId !== item.id + ) || ( + currentShouldBeRoom && ( + wantedUserId !== item.for_account || + wantedRoomId !== item.id + ) + ) ) - )) - ) - currentIndex = -1 // will trigger the correctTimer + ) + currentIndex = -1 // will trigger the correctTimer + }) }