From 11c1e1bc79f8405f91009e7ab6968bbcd8bef578 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 16 Jun 2019 09:35:53 +0800 Subject: [PATCH] html: enable copy on select --- html/src/components/terminal/index.tsx | 12 +++++++++--- src/index.html | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx index 4387c63..55aedc0 100644 --- a/html/src/components/terminal/index.tsx +++ b/html/src/components/terminal/index.tsx @@ -85,15 +85,15 @@ export default class Xterm extends Component { this.socket = new WebSocket(this.props.url, ['tty']); this.terminal = new Terminal(this.props.options); - const { socket, terminal, container } = this; + const { socket, terminal, container, fitAddon, overlayAddon } = this; socket.binaryType = 'arraybuffer'; socket.onopen = this.onSocketOpen; socket.onmessage = this.onSocketData; socket.onclose = this.onSocketClose; - terminal.loadAddon(this.fitAddon); - terminal.loadAddon(this.overlayAddon); + terminal.loadAddon(fitAddon); + terminal.loadAddon(overlayAddon); terminal.loadAddon(new WebLinksAddon()); terminal.onTitleChange((data) => { @@ -103,6 +103,12 @@ export default class Xterm extends Component { }); terminal.onData(this.onTerminalData); terminal.onResize(this.onTerminalResize); + if (document.queryCommandSupported && document.queryCommandSupported('copy')) { + terminal.onSelectionChange(() => { + overlayAddon.showOverlay('\u2702', 200); + document.execCommand('copy'); + }); + } terminal.open(container); terminal.focus(); diff --git a/src/index.html b/src/index.html index 8d41bc5..1587364 100644 --- a/src/index.html +++ b/src/index.html @@ -1 +1 @@ -ttyd - Terminal \ No newline at end of file +ttyd - Terminal \ No newline at end of file -- 2.43.4