diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-10 19:33:39 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-10 19:36:49 +0200 |
commit | 0bc2c12eecfb5b035c498272556f8fc6a39059a9 (patch) | |
tree | 5fa301a057a8daf50ea08b1a764b5253c98b9a97 /xP/public | |
parent | 3330683ad61be8524940c8932396a08b7062d205 (diff) | |
download | xK-0bc2c12eecfb5b035c498272556f8fc6a39059a9.tar.gz xK-0bc2c12eecfb5b035c498272556f8fc6a39059a9.tar.xz xK-0bc2c12eecfb5b035c498272556f8fc6a39059a9.zip |
xP: handle the M-Tab binding from xC
Diffstat (limited to 'xP/public')
-rw-r--r-- | xP/public/xP.js | 41 |
1 files 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() }) |