From e38f35c57870443dd3e77bf44af7ade606096ae9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 31 May 2021 18:26:04 +0200 Subject: [PATCH] Order buffers by priority in Alt+a --- keybindings.js | 10 +++++++--- state.js | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/keybindings.js b/keybindings.js index ac1b634..f46ebe5 100644 --- a/keybindings.js +++ b/keybindings.js @@ -27,16 +27,20 @@ export const keybindings = [ altKey: true, description: "Jump to next buffer with activity", execute: (app) => { - // TODO: order by priority, then by age + // TODO: order by age if same priority var firstServerBuffer = null; var target = null; for (var buf of app.state.buffers.values()) { if (!firstServerBuffer && buf.type === BufferType.SERVER) { firstServerBuffer = buf; } - if (buf.unread != Unread.NONE) { + + if (buf.unread === Unread.NONE) { + continue; + } + + if (!target || Unread.compare(buf.unread, target.unread) > 0) { target = buf; - break; } } if (!target) { diff --git a/state.js b/state.js index 34813db..41fdac9 100644 --- a/state.js +++ b/state.js @@ -15,13 +15,16 @@ export const Unread = { MESSAGE: "message", HIGHLIGHT: "highlight", - union(a, b) { + compare(a, b) { const priority = { [Unread.NONE]: 0, [Unread.MESSAGE]: 1, [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; }, };