From a561f4650b40507f23d679c20a6f3d7d94d07848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bottazini?= Date: Fri, 30 Sep 2016 14:30:11 +0200 Subject: [PATCH] Add Setting for modifier Keys cmdIsMeta and altIsMeta (#686) * Adds Setting for modifier Keys cmdIsMeta and altIsMeta * ModifierKeys setting for redux state * removing from default config modifierKeys --- lib/components/term.js | 1 + lib/components/terms.js | 3 ++- lib/containers/terms.js | 3 ++- lib/hterm.js | 18 ++++++++++++++++++ lib/reducers/ui.js | 10 +++++++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/components/term.js b/lib/components/term.js index 0eaf319e..87315994 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -61,6 +61,7 @@ export default class Term extends Component { } }; + this.term.modifierKeys = props.modifierKeys; // this.term.CursorNode_ is available at this point. this.term.setCursorShape(props.cursorShape); }; diff --git a/lib/components/terms.js b/lib/components/terms.js index d0bab64f..66f745b1 100644 --- a/lib/components/terms.js +++ b/lib/components/terms.js @@ -152,7 +152,8 @@ export default class Terms extends Component { onURLAbort: this.bind(this.props.onURLAbort, null, uid), bell: this.props.bell, bellSoundURL: this.props.bellSoundURL, - copyOnSelect: this.props.copyOnSelect + copyOnSelect: this.props.copyOnSelect, + modifierKeys: this.props.modifierKeys }); return (
{ diff --git a/lib/hterm.js b/lib/hterm.js index 03aefc39..9700c789 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -102,6 +102,24 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) { console.warn('Uncaught dead key on international keyboard', e); } + const modifierKeysConf = this.terminal.modifierKeys; + if (e.altKey && + e.code !== 'alt' && + e.code !== 'altLeft' && + e.code !== 'altRight' && + modifierKeysConf.altIsMeta) { + this.terminal.onVTKeystroke('\x1b' + String.fromCharCode(e.keyCode)); + e.preventDefault(); + } + + if (e.metaKey && + e.code !== 'MetaLeft' && + e.code !== 'MetaRight' && + modifierKeysConf.cmdIsMeta) { + this.terminal.onVTKeystroke('\x1b' + String.fromCharCode(e.keyCode)); + e.preventDefault(); + } + if (e.metaKey || e.altKey || (e.ctrlKey && e.code === 'Tab')) { return; } diff --git a/lib/reducers/ui.js b/lib/reducers/ui.js index 730a0166..6636849d 100644 --- a/lib/reducers/ui.js +++ b/lib/reducers/ui.js @@ -71,7 +71,11 @@ const initial = Immutable({ updateNotes: null, bell: 'SOUND', bellSoundURL: 'lib-resource:hterm/audio/bell', - copyOnSelect: false + copyOnSelect: false, + modifierKeys: { + altIsMeta: false, + cmdIsMeta: false + } }); const reducer = (state = initial, action) => { @@ -157,6 +161,10 @@ const reducer = (state = initial, action) => { } } + if (config.modifierKeys !== null) { + ret.modifierKeys = config.modifierKeys; + } + return ret; })()); break;