Fix keyboard shortcuts on Linux and Windows (#1058)

* `command` => `mod`

* `Option` => `Alt`

* Allow hterm to consume a keyboard event only if it's not a Hyper accelerator

* Remove `console.log`s

* Say no to bikeshedding

* We already clear the selection on `onKeyDown`

* Add comments

* Remove meaningless comment

* Add fullscreen shortcut for Windows and Linux

* Use the accelerators defined in `accelerators.js` for the app menu
This commit is contained in:
Matheus Fernandes 2016-11-30 18:19:45 -02:00 committed by Guillermo Rauch
parent 810e0a9806
commit be286c0d5a
4 changed files with 197 additions and 56 deletions

View file

@ -44,22 +44,22 @@ class Hyper extends Component {
const lastIndex = this.terms.getLastTermIndex();
const document = term.getTermDocument();
const keys = new Mousetrap(document);
keys.bind('command+1', moveTo.bind(this, 0));
keys.bind('command+2', moveTo.bind(this, 1));
keys.bind('command+3', moveTo.bind(this, 2));
keys.bind('command+4', moveTo.bind(this, 3));
keys.bind('command+5', moveTo.bind(this, 4));
keys.bind('command+6', moveTo.bind(this, 5));
keys.bind('command+7', moveTo.bind(this, 6));
keys.bind('command+8', moveTo.bind(this, 7));
keys.bind('command+9', moveTo.bind(this, lastIndex));
keys.bind('mod+1', moveTo.bind(this, 0));
keys.bind('mod+2', moveTo.bind(this, 1));
keys.bind('mod+3', moveTo.bind(this, 2));
keys.bind('mod+4', moveTo.bind(this, 3));
keys.bind('mod+5', moveTo.bind(this, 4));
keys.bind('mod+6', moveTo.bind(this, 5));
keys.bind('mod+7', moveTo.bind(this, 6));
keys.bind('mod+8', moveTo.bind(this, 7));
keys.bind('mod+9', moveTo.bind(this, lastIndex));
keys.bind('command+shift+left', moveLeft);
keys.bind('command+shift+right', moveRight);
keys.bind('command+shift+[', moveLeft);
keys.bind('command+shift+]', moveRight);
keys.bind('command+alt+left', moveLeft);
keys.bind('command+alt+right', moveRight);
keys.bind('mod+shift+left', moveLeft);
keys.bind('mod+shift+right', moveRight);
keys.bind('mod+shift+[', moveLeft);
keys.bind('mod+shift+]', moveRight);
keys.bind('mod+alt+left', moveLeft);
keys.bind('mod+alt+right', moveRight);
keys.bind('ctrl+shift+tab', moveLeft);
keys.bind('ctrl+tab', moveRight);
@ -68,10 +68,10 @@ class Hyper extends Component {
keys.bind('alt+right', bound('moveWordRight'));
keys.bind('alt+backspace', bound('deleteWordLeft'));
keys.bind('alt+del', bound('deleteWordRight'));
keys.bind('command+backspace', bound('deleteLine'));
keys.bind('command+left', bound('moveToStart'));
keys.bind('command+right', bound('moveToEnd'));
keys.bind('command+a', bound('selectAll'));
keys.bind('mod+backspace', bound('deleteLine'));
keys.bind('mod+left', bound('moveToStart'));
keys.bind('mod+right', bound('moveToEnd'));
keys.bind('mod+a', bound('selectAll'));
this.keys = keys;
}

View file

@ -1,6 +1,8 @@
import {hterm, lib} from 'hterm-umdjs';
import runes from 'runes';
import {isAccelerator} from '../app/accelerators';
import fromCharCode from './utils/key-code';
import selection from './utils/selection';
@ -164,7 +166,8 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
e.preventDefault();
}
if (e.metaKey || e.altKey || (e.ctrlKey && e.code === 'Tab')) {
if (isAccelerator(e)) {
// hterm shouldn't consume a hyper accelerator
return;
}
if ((!e.ctrlKey || e.code !== 'ControlLeft') &&
@ -176,15 +179,6 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
return oldKeyDown.call(this, e);
};
const oldKeyPress = hterm.Keyboard.prototype.onKeyPress_;
hterm.Keyboard.prototype.onKeyPress_ = function (e) {
if (e.metaKey) {
return;
}
selection.clear(this.terminal);
return oldKeyPress.call(this, e);
};
// we re-implement `wipeContents` to preserve the line
// and cursor position that the client is in.
// otherwise the user ends up with a completely clear