All CTRL+V in terminal

Fixes https://github.com/pybricks/support/issues/172
This commit is contained in:
David Lechner
2020-12-10 16:28:43 -06:00
parent 20ca3d1377
commit 98feab2555
+11 -1
View File
@@ -52,9 +52,19 @@ class Terminal extends React.Component<TerminalProps> {
this.fitAddon = new FitAddon();
this.xterm.loadAddon(this.fitAddon);
this.xterm.onData((d) => this.props.onData(d));
this.xterm.attachCustomKeyEventHandler(this.handleKeyEvent);
this.terminalRef = React.createRef();
}
private handleKeyEvent = (e: KeyboardEvent): boolean => {
if (e.key === 'v' && e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey) {
// this allows CTRL+V to be handled by the browser instead of sending
// a control character to the terminal.
return false;
}
return true;
};
private handleKeyDownEvent = (e: KeyboardEvent): void => {
// implement CTRL+SHIFT+C keyboard shortcut for copying text from terminal
if (e.key === 'C' && e.ctrlKey && e.shiftKey && !e.altKey && !e.metaKey) {
@@ -125,7 +135,7 @@ class Terminal extends React.Component<TerminalProps> {
}}
text={i18n.translate(TerminalStringId.Paste)}
icon="clipboard"
label={/mac/i.test(navigator.platform) ? 'Cmd-V' : 'Ctrl-Shift-V'}
label={/mac/i.test(navigator.platform) ? 'Cmd-V' : 'Ctrl-V'}
/>
<MenuDivider />
<MenuItem