Add shorcut to navigate between channels with undread msgs

This commit is contained in:
Nachtalb 2021-05-20 20:46:24 +02:00 committed by Nachtalb
parent ae6bae69ac
commit daabb76781
No known key found for this signature in database
GPG key ID: FB8B6CA09AE73612
2 changed files with 49 additions and 0 deletions

View file

@ -179,6 +179,26 @@
</div>
</div>
<div class="help-item">
<div class="subject">
<span v-if="!isApple"><kbd>Alt</kbd> <kbd>Ctrl</kbd> <kbd></kbd></span>
<span v-else><kbd></kbd> <kbd></kbd> <kbd></kbd></span>
</div>
<div class="description">
<p>Switch to the next window with unread messages in the channel list.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<span v-if="!isApple"><kbd>Alt</kbd> <kbd>Ctrl</kbd> <kbd></kbd></span>
<span v-else><kbd></kbd> <kbd></kbd> <kbd></kbd></span>
</div>
<div class="description">
<p>Switch to the previous window with unread messages in the channel list.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<span v-if="!isApple"><kbd>Alt</kbd> <kbd>A</kbd></span>

View file

@ -83,6 +83,35 @@ Mousetrap.bind(["alt+shift+up", "alt+shift+down"], function (e, keys) {
return false;
});
// Switch to the next/previous unread chat
Mousetrap.bind(["alt+mod+up", "alt+mod+down"], function (e, keys) {
if (isIgnoredKeybind(e)) {
return true;
}
const channels = store.state.networks
.map((net) =>
net.channels.filter(
(chan) => chan.unread || chan === store.state.activeChannel?.channel
)
)
.flat();
if (channels.length === 0) {
return;
}
let index = channels.findIndex((chan) => chan === store.state.activeChannel?.channel);
const length = channels.length;
const direction = keys.split("+").pop() === "up" ? -1 : 1;
index = (((index + direction) % length) + length) % length;
jumpToChannel(channels[index]);
return false;
});
// Jump to the first window with a highlight in it, or the first with unread
// activity if there are none with highlights.
Mousetrap.bind(["alt+a"], function (e) {