xP: bind M-h to toggle history, and adjust focus
This commit is contained in:
parent
0bc2c12eec
commit
95aa89ee97
@ -137,7 +137,7 @@ let bufferCurrent = undefined
|
|||||||
let bufferLog = undefined
|
let bufferLog = undefined
|
||||||
let bufferAutoscroll = true
|
let bufferAutoscroll = true
|
||||||
|
|
||||||
function resetBufferStats(b) {
|
function bufferResetStats(b) {
|
||||||
b.newMessages = 0
|
b.newMessages = 0
|
||||||
b.newUnimportantMessages = 0
|
b.newUnimportantMessages = 0
|
||||||
b.highlighted = false
|
b.highlighted = false
|
||||||
@ -147,6 +147,29 @@ function bufferActivate(name) {
|
|||||||
rpc.send({command: 'BufferActivate', bufferName: 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
|
let connecting = true
|
||||||
rpc.connect().then(result => {
|
rpc.connect().then(result => {
|
||||||
buffers.clear()
|
buffers.clear()
|
||||||
@ -175,7 +198,7 @@ rpc.addEventListener('BufferUpdate', event => {
|
|||||||
let e = event.detail, b = buffers.get(e.bufferName)
|
let e = event.detail, b = buffers.get(e.bufferName)
|
||||||
if (b === undefined) {
|
if (b === undefined) {
|
||||||
buffers.set(e.bufferName, (b = {lines: []}))
|
buffers.set(e.bufferName, (b = {lines: []}))
|
||||||
resetBufferStats(b)
|
bufferResetStats(b)
|
||||||
}
|
}
|
||||||
b.hideUnimportant = e.hideUnimportant
|
b.hideUnimportant = e.hideUnimportant
|
||||||
})
|
})
|
||||||
@ -206,7 +229,7 @@ rpc.addEventListener('BufferRemove', event => {
|
|||||||
rpc.addEventListener('BufferActivate', event => {
|
rpc.addEventListener('BufferActivate', event => {
|
||||||
let old = buffers.get(bufferCurrent)
|
let old = buffers.get(bufferCurrent)
|
||||||
if (old !== undefined)
|
if (old !== undefined)
|
||||||
resetBufferStats(old)
|
bufferResetStats(old)
|
||||||
|
|
||||||
bufferLast = bufferCurrent
|
bufferLast = bufferCurrent
|
||||||
let e = event.detail, b = buffers.get(e.bufferName)
|
let e = event.detail, b = buffers.get(e.bufferName)
|
||||||
@ -307,26 +330,11 @@ let Toolbar = {
|
|||||||
bufferAutoscroll = !bufferAutoscroll
|
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 => {
|
view: vnode => {
|
||||||
return m('.toolbar', {}, [
|
return m('.toolbar', {}, [
|
||||||
m('button', {onclick: Toolbar.toggleAutoscroll},
|
m('button', {onclick: Toolbar.toggleAutoscroll},
|
||||||
bufferAutoscroll ? 'Scroll lock' : 'Scroll unlock'),
|
bufferAutoscroll ? 'Scroll lock' : 'Scroll unlock'),
|
||||||
m('button', {onclick: Toolbar.toggleLog},
|
m('button', {onclick: event => bufferToggleLog()},
|
||||||
bufferLog === undefined ? 'Show log' : 'Hide log'),
|
bufferLog === undefined ? 'Show log' : 'Hide log'),
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
@ -500,8 +508,8 @@ let Buffer = {
|
|||||||
|
|
||||||
let Log = {
|
let Log = {
|
||||||
oncreate: vnode => {
|
oncreate: vnode => {
|
||||||
if (vnode.dom !== undefined)
|
vnode.dom.scrollTop = vnode.dom.scrollHeight
|
||||||
vnode.dom.scrollTop = vnode.dom.scrollHeight
|
vnode.dom.focus()
|
||||||
},
|
},
|
||||||
|
|
||||||
linkify: text => {
|
linkify: text => {
|
||||||
@ -629,6 +637,8 @@ document.addEventListener('keydown', event => {
|
|||||||
if (event.altKey && event.key == 'Tab') {
|
if (event.altKey && event.key == 'Tab') {
|
||||||
if (bufferLast !== undefined)
|
if (bufferLast !== undefined)
|
||||||
bufferActivate(bufferLast)
|
bufferActivate(bufferLast)
|
||||||
|
} else if (event.altKey && event.key == 'h') {
|
||||||
|
bufferToggleLog()
|
||||||
} else if (event.altKey && event.key == 'a') {
|
} else if (event.altKey && event.key == 'a') {
|
||||||
for (const [name, b] of buffers)
|
for (const [name, b] of buffers)
|
||||||
if (name !== bufferCurrent && b.newMessages) {
|
if (name !== bufferCurrent && b.newMessages) {
|
||||||
|
Loading…
Reference in New Issue
Block a user