terminal: support ctrl+shift+c/v for copy paste

This commit is contained in:
Johannes Zellner
2023-07-18 18:05:07 +02:00
parent 024a9c6e2b
commit 978faa1f68

View File

@@ -241,7 +241,7 @@ export default {
// Let the browser handle paste
this.terminal.attachCustomKeyEventHandler(function (e) {
if (e.key === 'v' && (e.ctrlKey || e.metaKey)) return false;
if (e.key === 'V' && (e.ctrlKey || e.metaKey)) return false;
});
// websocket cannot use relative urls
@@ -250,6 +250,11 @@ export default {
this.terminal.loadAddon(new AttachAddon(this.socket));
// Let the browser handle paste
// this.terminal.attachCustomKeyEventHandler((event) => {
// if (event.key === 'V' && (event.ctrlKey || event.metaKey)) return false;
// });
this.socket.addEventListener('open', (event) => {
this.connected = true;
});
@@ -308,6 +313,21 @@ export default {
window.document.title = `Terminal - ${this.name}`;
window.addEventListener('keydown', (event) => {
if (event.key === 'C' && (event.ctrlKey || event.metaKey)) { // ctrl shift c
event.preventDefault();
if (!this.terminal) return;
// execCommand('copy') would copy any selection from the page, so do this only if terminal has a selection
if (!this.terminal.getSelection()) return;
document.execCommand('copy');
this.terminal.focus();
}
});
this.connect();
}
};