diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-13 03:18:12 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-13 03:21:41 +0200 |
commit | a551e911ab54f5b1f56f837c3ebed42ef86fb4a1 (patch) | |
tree | ed0106fde5333a5627ff1bdcbb8f2e1f205cf1b7 /xP/public/xP.js | |
parent | a61789637a5af03b06655c9ce03a92ddd57fe383 (diff) | |
download | xK-a551e911ab54f5b1f56f837c3ebed42ef86fb4a1.tar.gz xK-a551e911ab54f5b1f56f837c3ebed42ef86fb4a1.tar.xz xK-a551e911ab54f5b1f56f837c3ebed42ef86fb4a1.zip |
xP: adjust buffer list iteration and styling
M-a and M-! should iterate, rather than keep jumping back
to the same buffers.
The current item wasn't visible enough,
and it jumped around in my 1.5-scale Firefox.
Diffstat (limited to 'xP/public/xP.js')
-rw-r--r-- | xP/public/xP.js | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index 2c4932b..6672231 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -841,21 +841,25 @@ document.addEventListener('keydown', event => { if (rpc.ws == undefined || !hasShortcutModifiers(event)) return - let names = undefined + // Rotate names so that the current buffer comes first. + let names = [...buffers.keys()] + names.push.apply(names, + names.splice(0, names.findIndex(name => name == bufferCurrent))) + switch (event.key) { case 'h': bufferToggleLog() break case 'a': - for (const [name, b] of buffers) - if (name !== bufferCurrent && b.newMessages) { + for (const name of names.slice(1)) + if (buffers.get(name).newMessages) { bufferActivate(name) break } break case '!': - for (const [name, b] of buffers) - if (name !== bufferCurrent && b.highlighted) { + for (const name of names.slice(1)) + if (buffers.get(name).highlighted) { bufferActivate(name) break } @@ -865,20 +869,12 @@ document.addEventListener('keydown', event => { bufferActivate(bufferLast) break case 'PageUp': - names = [...buffers.keys()] - for (let i = 0; i < names.length; i++) - if (names[i] === bufferCurrent) { - bufferActivate(names.at(--i)) - break - } + if (names.length > 1) + bufferActivate(names.at(-1)) break case 'PageDown': - names = [...buffers.keys()] - for (let i = 0; i < names.length; i++) - if (names[i] === bufferCurrent) { - bufferActivate(names.at(++i) || names[0]) - break - } + if (names.length > 1) + bufferActivate(names.at(+1)) break default: return |