Order buffers by priority in Alt+a

This commit is contained in:
Simon Ser 2021-05-31 18:26:04 +02:00
parent 958b6bf120
commit e38f35c578
2 changed files with 12 additions and 5 deletions

View file

@ -27,16 +27,20 @@ export const keybindings = [
altKey: true, altKey: true,
description: "Jump to next buffer with activity", description: "Jump to next buffer with activity",
execute: (app) => { execute: (app) => {
// TODO: order by priority, then by age // TODO: order by age if same priority
var firstServerBuffer = null; var firstServerBuffer = null;
var target = null; var target = null;
for (var buf of app.state.buffers.values()) { for (var buf of app.state.buffers.values()) {
if (!firstServerBuffer && buf.type === BufferType.SERVER) { if (!firstServerBuffer && buf.type === BufferType.SERVER) {
firstServerBuffer = buf; firstServerBuffer = buf;
} }
if (buf.unread != Unread.NONE) {
if (buf.unread === Unread.NONE) {
continue;
}
if (!target || Unread.compare(buf.unread, target.unread) > 0) {
target = buf; target = buf;
break;
} }
} }
if (!target) { if (!target) {

View file

@ -15,13 +15,16 @@ export const Unread = {
MESSAGE: "message", MESSAGE: "message",
HIGHLIGHT: "highlight", HIGHLIGHT: "highlight",
union(a, b) { compare(a, b) {
const priority = { const priority = {
[Unread.NONE]: 0, [Unread.NONE]: 0,
[Unread.MESSAGE]: 1, [Unread.MESSAGE]: 1,
[Unread.HIGHLIGHT]: 2, [Unread.HIGHLIGHT]: 2,
}; };
return (priority[a] > priority[b]) ? a : b; return priority[a] - priority[b];
},
union(a, b) {
return (Unread.compare(a, b) > 0) ? a : b;
}, },
}; };