From 33c9edc9a3e32f7c694960d07a7f81a0a5761d42 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 20 Feb 2023 19:26:53 +0100 Subject: [PATCH] Don't switch to invisible first/last room on Ctrl+PgUp/PgDn If you're on the first visible room and try to switch to the previous one (or on the last visible room switching to the next one), the first (or last) room in the list is incorrectly selected even if it's not currently visible. Fix this by not first entering each room and then checking whether it is the one we really wanted, but iterating until we find a room that we want and only entering it then. --- src/qml/Page/RoomListPage.qml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/qml/Page/RoomListPage.qml b/src/qml/Page/RoomListPage.qml index dd94fb665..0dfaa7282 100644 --- a/src/qml/Page/RoomListPage.qml +++ b/src/qml/Page/RoomListPage.qml @@ -132,17 +132,25 @@ Kirigami.ScrollablePage { } function goToNextRoom() { - do { - listView.incrementCurrentIndex(); - } while (!listView.currentItem.visible && listView.currentIndex !== listView.count - 1) - listView.currentItem.action.trigger(); + let index = listView.currentIndex; + while (index++ !== listView.count - 1) { + if (listView.itemAtIndex(index).visible) { + listView.currentIndex = index; + listView.currentItem.action.trigger(); + return; + } + } } function goToPreviousRoom() { - do { - listView.decrementCurrentIndex(); - } while (!listView.currentItem.visible && listView.currentIndex !== 0) - listView.currentItem.action.trigger(); + let index = listView.currentIndex; + while (index-- !== 0) { + if (listView.itemAtIndex(index).visible) { + listView.currentIndex = index; + listView.currentItem.action.trigger(); + return; + } + } } titleDelegate: collapsedMode ? empty : searchField