Add keybinds for previous/next unread/mention room

This commit is contained in:
miruka
2020-05-14 01:21:44 -04:00
parent 200f0c33a8
commit 974478f576
3 changed files with 58 additions and 14 deletions

View File

@@ -102,6 +102,26 @@ HListView {
showItemAtIndex(accountIndice[currentUserId] + 1 + index)
}
function cycleUnreadRooms(forward=true, mentions=false) {
const prop = mentions ? "mentions" : "unreads"
const start = currentIndex === -1 ? 0 : currentIndex
let index = start
while (true) {
index += forward ? 1 : -1
if (index < 0) index = model.count - 1
if (index > model.count - 1) index = 0
if (index === start) return false
const item = model.get(index)
if (item.type === "Room" && item[prop]) {
currentIndex = index
return true
}
}
}
function setCorrectCurrentItem() {
if (! currentShouldBeRoom && ! currentShouldBeAccount) {
@@ -165,6 +185,27 @@ HListView {
onActivated: { incrementCurrentIndex(); showItemLimiter.restart() }
}
HShortcut {
sequences: window.settings.keys.goToPreviousUnreadRoom
onActivated: { cycleUnreadRooms(false) && showItemLimiter.restart() }
}
HShortcut {
sequences: window.settings.keys.goToNextUnreadRoom
onActivated: { cycleUnreadRooms(true) && showItemLimiter.restart() }
}
HShortcut {
sequences: window.settings.keys.goToPreviousMentionedRoom
onActivated: cycleUnreadRooms(false, true) && showItemLimiter.restart()
}
HShortcut {
sequences: window.settings.keys.goToNextMentionedRoom
onActivated: cycleUnreadRooms(true, true) && showItemLimiter.restart()
}
Repeater {
model: Object.keys(window.settings.keys.focusRoomAtIndex)