Replace ^C with ^ in soft keyboard extension bar

box-drawing
cpsdqs 7 years ago
parent 310033b911
commit 842d1fd93c
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 18
      js/term/input.js
  2. 22
      js/term/soft_keyboard.js

@ -256,16 +256,23 @@ module.exports = function (conn, screen) {
'F5', 'F11', 'F12', 'Shift+F5'
]
let softModifiers = {
alt: false,
ctrl: false,
meta: false,
shift: false
}
const handleKeyDown = function (e) {
if (!shouldAcceptEvent()) return
if (cfg.no_keys) return
let modifiers = []
// sorted alphabetically
if (e.altKey) modifiers.push('Alt')
if (e.ctrlKey) modifiers.push('Control')
if (e.metaKey) modifiers.push('Meta')
if (e.shiftKey) modifiers.push('Shift')
if (e.altKey || softModifiers.alt) modifiers.push('Alt')
if (e.ctrlKey || softModifiers.ctrl) modifiers.push('Control')
if (e.metaKey || softModifiers.meta) modifiers.push('Meta')
if (e.shiftKey || softModifiers.shift) modifiers.push('Shift')
let key = KEY_NAMES[e.which] || e.key
@ -455,7 +462,8 @@ module.exports = function (conn, screen) {
cfg.no_keys = yes
},
handleKeyDown
handleKeyDown,
softModifiers
}
return input
}

@ -122,7 +122,7 @@ module.exports = function (screen, input) {
'↓': 0x28,
'↑': 0x26,
'→': 0x27,
'^C': { which: 0x43, ctrlKey: true }
Control: 'ctrl'
}
for (const shortcut in shortcuts) {
@ -132,12 +132,24 @@ module.exports = function (screen, input) {
shortcutBar.appendChild(button)
const key = shortcuts[shortcut]
button.addEventListener('click', e => {
button.addEventListener('touchstart', e => {
if (typeof key === 'string') {
// modifier button
input.softModifiers[key] = true
// prevent default. This prevents scrolling, but also prevents the
// selection popup
e.preventDefault()
let fakeEvent = key
if (typeof key === 'number') fakeEvent = { which: key }
fakeEvent.preventDefault = () => {}
}
})
button.addEventListener('touchend', e => {
e.preventDefault()
if (typeof key === 'number') {
let fakeEvent = { which: key, preventDefault: () => {} }
input.handleKeyDown(fakeEvent)
} else if (typeof key === 'string') {
input.softModifiers[key] = false
}
})
}
}

Loading…
Cancel
Save