From 0bc2c12eecfb5b035c498272556f8fc6a39059a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Sat, 10 Sep 2022 19:33:39 +0200 Subject: [PATCH] xP: handle the M-Tab binding from xC --- xP/public/xP.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/xP/public/xP.js b/xP/public/xP.js index 5f73b5f..c2e0e03 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -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() })