From 98feab2555f5ce547a8fb4539f95bcff73ee0e23 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 10 Dec 2020 16:27:02 -0600 Subject: [PATCH] All CTRL+V in terminal Fixes https://github.com/pybricks/support/issues/172 --- src/components/Terminal.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/Terminal.tsx b/src/components/Terminal.tsx index 7bf3558c..135a1fe8 100644 --- a/src/components/Terminal.tsx +++ b/src/components/Terminal.tsx @@ -52,9 +52,19 @@ class Terminal extends React.Component { 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 { }} 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'} />