From cb651f6492a67e660cbed16e97d50bdbb48535e5 Mon Sep 17 00:00:00 2001 From: James Hall Date: Wed, 10 Aug 2016 18:37:35 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20international=20tilde=20character,=20and?= =?UTF-8?q?=20`=20and=20=C2=B4=20(#584)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * This fixes many more keyboard layouts * Make backticks work on German keyboards * Add italian keyboard layout, and also log when uncaught dead key occurs --- lib/hterm.js | 67 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/lib/hterm.js b/lib/hterm.js index 7c9ab102..bec25a15 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -34,26 +34,55 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) { * These keys are sent through as 'Dead' keys, as they're used as modifiers. * Ignore that and insert the correct character. */ - if (e.key === 'Dead' && e.code === 'Quote' && e.shiftKey === false) { - this.terminal.onVTKeystroke("'"); - return; - } - if (e.key === 'Dead' && e.code === 'Quote' && e.shiftKey === true) { - this.terminal.onVTKeystroke('"'); - return; - } - if (e.key === 'Dead' && (e.code === 'IntlBackslash' || e.code === 'Backquote') && e.shiftKey === true) { - this.terminal.onVTKeystroke('~'); - return; - } - if (e.key === 'Dead' && (e.code === 'IntlBackslash' || e.code === 'Backquote') && e.shiftKey === false) { - this.terminal.onVTKeystroke('`'); - return; - } - if (e.key === 'Dead' && e.code === 'Digit6') { - this.terminal.onVTKeystroke('^'); - return; + if (e.key === 'Dead') { + if (e.code === 'Quote' && e.shiftKey === false) { + this.terminal.onVTKeystroke("'"); + return; + } + if (e.code === 'Quote' && e.shiftKey === true) { + this.terminal.onVTKeystroke('"'); + return; + } + if ((e.code === 'IntlBackslash' || e.code === 'Backquote') && e.shiftKey === true) { + this.terminal.onVTKeystroke('~'); + return; + } + // This key is also a tilde on all tested keyboards + if (e.code === 'KeyN' && e.altKey === true) { + this.terminal.onVTKeystroke('~'); + return; + } + if ((e.code === 'IntlBackslash' || e.code === 'Backquote') && e.shiftKey === false) { + this.terminal.onVTKeystroke('`'); + return; + } + if (e.code === 'Digit6') { + this.terminal.onVTKeystroke('^'); + return; + } + // German keyboard layout + if (e.code === 'Equal' && e.shiftKey === false) { + this.terminal.onVTKeystroke('´'); + return; + } + if (e.code === 'Equal' && e.shiftKey === true) { + this.terminal.onVTKeystroke('`'); + return; + } + // Italian keyboard layout + if (e.code === 'Digit9' && e.altKey === true) { + this.terminal.onVTKeystroke('`'); + return; + } + if (e.code === 'Digit8' && e.altKey === true) { + this.terminal.onVTKeystroke('´'); + // To fix issue with changing the terminal prompt + e.preventDefault(); + return; + } + console.warn('Uncaught dead key on international keyboard', e); } + if (e.metaKey || e.altKey) { return; }