xP: handle the M-Tab binding from xC

This commit is contained in:
Přemysl Eric Janouch 2022-09-10 19:33:39 +02:00
parent 3330683ad6
commit 0bc2c12eec
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 25 additions and 16 deletions

View File

@ -132,6 +132,7 @@ class RelayRpc extends EventTarget {
let rpc = new RelayRpc(proxy)
let buffers = new Map()
let bufferLast = undefined
let bufferCurrent = undefined
let bufferLog = undefined
let bufferAutoscroll = true
@ -142,9 +143,14 @@ function resetBufferStats(b) {
b.highlighted = false
}
function bufferActivate(name) {
rpc.send({command: 'BufferActivate', bufferName: name})
}
let connecting = true
rpc.connect().then(result => {
buffers.clear()
bufferLast = undefined
bufferCurrent = undefined
bufferLog = undefined
bufferAutoscroll = true
@ -193,6 +199,8 @@ rpc.addEventListener('BufferRename', event => {
rpc.addEventListener('BufferRemove', event => {
let e = event.detail
buffers.delete(e.bufferName)
if (e.bufferName === bufferLast)
bufferLast = undefined
})
rpc.addEventListener('BufferActivate', event => {
@ -200,6 +208,7 @@ rpc.addEventListener('BufferActivate', event => {
if (old !== undefined)
resetBufferStats(old)
bufferLast = bufferCurrent
let e = event.detail, b = buffers.get(e.bufferName)
bufferCurrent = e.bufferName
bufferLog = undefined
@ -324,10 +333,6 @@ let Toolbar = {
}
let BufferList = {
activate: name => {
rpc.send({command: 'BufferActivate', bufferName: name})
},
view: vnode => {
let items = Array.from(buffers, ([name, b]) => {
let classes = [], displayName = name
@ -342,7 +347,7 @@ let BufferList = {
}
}
return m('.item', {
onclick: event => BufferList.activate(name),
onclick: event => bufferActivate(name),
class: classes.join(' '),
}, displayName)
})
@ -578,11 +583,13 @@ let Input = {
let handled = false
switch (event.keyCode) {
case 9:
if (!event.shiftKey)
if (!event.ctrlKey && !event.metaKey && !event.altKey &&
!event.shiftKey)
handled = Input.complete(textarea)
break
case 13:
if (!event.shiftKey)
if (!event.ctrlKey && !event.metaKey && !event.altKey &&
!event.shiftKey)
handled = Input.submit(textarea)
break
}
@ -619,21 +626,23 @@ document.addEventListener('keydown', event => {
if (rpc.ws == undefined || event.ctrlKey || event.metaKey)
return
if (event.altKey && event.key == 'a') {
if (event.altKey && event.key == 'Tab') {
if (bufferLast !== undefined)
bufferActivate(bufferLast)
} else if (event.altKey && event.key == 'a') {
for (const [name, b] of buffers)
if (name !== bufferCurrent && b.newMessages) {
rpc.send({command: 'BufferActivate', bufferName: name})
bufferActivate(name)
break
}
return event.preventDefault()
}
if (event.altKey && event.key == '!') {
} else if (event.altKey && event.key == '!') {
for (const [name, b] of buffers)
if (name !== bufferCurrent && b.highlighted) {
rpc.send({command: 'BufferActivate', bufferName: name})
bufferActivate(name)
break
}
return event.preventDefault()
}
} else
return
event.preventDefault()
})