diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-10 20:38:32 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-10 20:39:03 +0200 |
commit | 95aa89ee97872caa98669f2e64e6b718ce5cf2e8 (patch) | |
tree | 7bda5dcba2e03934de5e64c006bd02078a9aac89 /xP/public | |
parent | 0bc2c12eecfb5b035c498272556f8fc6a39059a9 (diff) | |
download | xK-95aa89ee97872caa98669f2e64e6b718ce5cf2e8.tar.gz xK-95aa89ee97872caa98669f2e64e6b718ce5cf2e8.tar.xz xK-95aa89ee97872caa98669f2e64e6b718ce5cf2e8.zip |
xP: bind M-h to toggle history, and adjust focus
Diffstat (limited to 'xP/public')
-rw-r--r-- | xP/public/xP.js | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index c2e0e03..4c740ba 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -137,7 +137,7 @@ let bufferCurrent = undefined let bufferLog = undefined let bufferAutoscroll = true -function resetBufferStats(b) { +function bufferResetStats(b) { b.newMessages = 0 b.newUnimportantMessages = 0 b.highlighted = false @@ -147,6 +147,29 @@ function bufferActivate(name) { rpc.send({command: 'BufferActivate', bufferName: name}) } +function bufferToggleLog() { + if (bufferLog) { + setTimeout(() => + document.getElementById('input')?.focus()) + + bufferLog = undefined + m.redraw() + return + } + + let name = bufferCurrent + rpc.send({ + command: 'BufferLog', + bufferName: name, + }).then(resp => { + if (bufferCurrent !== name) + return + + bufferLog = rpc.base64decode(resp.log) + m.redraw() + }) +} + let connecting = true rpc.connect().then(result => { buffers.clear() @@ -175,7 +198,7 @@ rpc.addEventListener('BufferUpdate', event => { let e = event.detail, b = buffers.get(e.bufferName) if (b === undefined) { buffers.set(e.bufferName, (b = {lines: []})) - resetBufferStats(b) + bufferResetStats(b) } b.hideUnimportant = e.hideUnimportant }) @@ -206,7 +229,7 @@ rpc.addEventListener('BufferRemove', event => { rpc.addEventListener('BufferActivate', event => { let old = buffers.get(bufferCurrent) if (old !== undefined) - resetBufferStats(old) + bufferResetStats(old) bufferLast = bufferCurrent let e = event.detail, b = buffers.get(e.bufferName) @@ -307,26 +330,11 @@ let Toolbar = { bufferAutoscroll = !bufferAutoscroll }, - toggleLog: () => { - if (bufferLog) { - bufferLog = undefined - return - } - - rpc.send({ - command: 'BufferLog', - bufferName: bufferCurrent, - }).then(resp => { - bufferLog = rpc.base64decode(resp.log) - m.redraw() - }) - }, - view: vnode => { return m('.toolbar', {}, [ m('button', {onclick: Toolbar.toggleAutoscroll}, bufferAutoscroll ? 'Scroll lock' : 'Scroll unlock'), - m('button', {onclick: Toolbar.toggleLog}, + m('button', {onclick: event => bufferToggleLog()}, bufferLog === undefined ? 'Show log' : 'Hide log'), ]) }, @@ -500,8 +508,8 @@ let Buffer = { let Log = { oncreate: vnode => { - if (vnode.dom !== undefined) - vnode.dom.scrollTop = vnode.dom.scrollHeight + vnode.dom.scrollTop = vnode.dom.scrollHeight + vnode.dom.focus() }, linkify: text => { @@ -629,6 +637,8 @@ document.addEventListener('keydown', event => { if (event.altKey && event.key == 'Tab') { if (bufferLast !== undefined) bufferActivate(bufferLast) + } else if (event.altKey && event.key == 'h') { + bufferToggleLog() } else if (event.altKey && event.key == 'a') { for (const [name, b] of buffers) if (name !== bufferCurrent && b.newMessages) { |