From 842d1fd93c0639f32570fc798ef289c4a18fc446 Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 24 Sep 2017 21:18:08 +0200 Subject: [PATCH] Replace ^C with ^ in soft keyboard extension bar --- js/term/input.js | 18 +++++++++++++----- js/term/soft_keyboard.js | 24 ++++++++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/js/term/input.js b/js/term/input.js index dff344c..e31b827 100644 --- a/js/term/input.js +++ b/js/term/input.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 } diff --git a/js/term/soft_keyboard.js b/js/term/soft_keyboard.js index 6cb3a77..73ed82e 100644 --- a/js/term/soft_keyboard.js +++ b/js/term/soft_keyboard.js @@ -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() + } + }) + button.addEventListener('touchend', e => { e.preventDefault() - let fakeEvent = key - if (typeof key === 'number') fakeEvent = { which: key } - fakeEvent.preventDefault = () => {} - input.handleKeyDown(fakeEvent) + if (typeof key === 'number') { + let fakeEvent = { which: key, preventDefault: () => {} } + input.handleKeyDown(fakeEvent) + } else if (typeof key === 'string') { + input.softModifiers[key] = false + } }) } }