From c0c86c67b612267b880c650ff27ae2b2b17420d6 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Wed, 22 Feb 2023 15:47:33 +0100 Subject: [PATCH] Alt+Shift+Up/Down to switch to previous/next unread room This is the same key combination as commonly used by other chat clients such as Element, Slack and Discord. For consistency, also add the same Alt+Up/Down shortcut as used in thes other clients as aliases for switching rooms without considering the unread status. --- src/qml/Page/RoomListPage.qml | 26 ++++++++++++++++++++++---- src/qml/main.qml | 18 ++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/qml/Page/RoomListPage.qml b/src/qml/Page/RoomListPage.qml index 0dfaa7282..2c5ccee1b 100644 --- a/src/qml/Page/RoomListPage.qml +++ b/src/qml/Page/RoomListPage.qml @@ -131,10 +131,10 @@ Kirigami.ScrollablePage { } } - function goToNextRoom() { + function goToNextRoomFiltered(condition) { let index = listView.currentIndex; while (index++ !== listView.count - 1) { - if (listView.itemAtIndex(index).visible) { + if (condition(listView.itemAtIndex(index))) { listView.currentIndex = index; listView.currentItem.action.trigger(); return; @@ -142,10 +142,10 @@ Kirigami.ScrollablePage { } } - function goToPreviousRoom() { + function goToPreviousRoomFiltered(condition) { let index = listView.currentIndex; while (index-- !== 0) { - if (listView.itemAtIndex(index).visible) { + if (condition(listView.itemAtIndex(index))) { listView.currentIndex = index; listView.currentItem.action.trigger(); return; @@ -153,6 +153,22 @@ Kirigami.ScrollablePage { } } + function goToNextRoom() { + goToNextRoomFiltered((item) => item.visible); + } + + function goToPreviousRoom() { + goToPreviousRoomFiltered((item) => item.visible); + } + + function goToNextUnreadRoom() { + goToNextRoomFiltered((item) => (item.visible && item.hasUnread)); + } + + function goToPreviousUnreadRoom() { + goToPreviousRoomFiltered((item) => (item.visible && item.hasUnread)); + } + titleDelegate: collapsedMode ? empty : searchField Component { @@ -428,6 +444,8 @@ Kirigami.ScrollablePage { }) menu.open() } + + readonly property bool hasUnread: unreadCount > 0 } } } diff --git a/src/qml/main.qml b/src/qml/main.qml index 7d903525c..9975dab72 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -318,18 +318,32 @@ Kirigami.ApplicationWindow { id: roomList Shortcut { - sequences: ["Ctrl+PgUp", "Ctrl+Backtab"] + sequences: ["Ctrl+PgUp", "Ctrl+Backtab", "Alt+Up"] onActivated: { roomList.goToPreviousRoom(); } } Shortcut { - sequences: ["Ctrl+PgDown", "Ctrl+Tab"] + sequences: ["Ctrl+PgDown", "Ctrl+Tab", "Alt+Down"] onActivated: { roomList.goToNextRoom(); } } + + Shortcut { + sequence: "Alt+Shift+Up" + onActivated: { + roomList.goToPreviousUnreadRoom(); + } + } + + Shortcut { + sequence: "Alt+Shift+Down" + onActivated: { + roomList.goToNextUnreadRoom(); + } + } } }