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.
This commit is contained in:
Přemysl Eric Janouch 2022-09-13 03:18:12 +02:00
parent a61789637a
commit a551e911ab
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 15 additions and 23 deletions

View File

@ -56,7 +56,7 @@ button {
.list {
overflow-y: auto;
border-right: 1px solid #ccc;
border-right: 2px solid #ccc;
min-width: 10em;
flex-shrink: 0;
}
@ -72,11 +72,7 @@ button {
}
.item.current {
font-style: italic;
background: #f8f8f8;
border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
margin-top: -1px;
margin-bottom: -1px;
background: #eee;
}
/* Only Firefox currently supports align-content: safe end, thus this. */

View File

@ -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