Add Ctrl+Insert and Shift+Insert as new Copy & Paste hot keys. Fixed the problem that pasted data was not send to the remote

This commit is contained in:
NI
2020-08-15 21:57:43 +08:00
parent d86c92867c
commit 5fa3616a73

View File

@@ -129,6 +129,7 @@ class Term {
constructor(control) {
const resizeDelayInterval = 500;
this.control = control;
this.closed = false;
this.fontSize = termDefaultFontSize;
this.term = new Terminal({
@@ -145,7 +146,7 @@ class Term {
this.term.loadAddon(new WebLinksAddon());
this.term.setOption("theme", {
background: control.activeColor(),
background: this.control.activeColor(),
});
this.term.onData((data) => {
@@ -153,7 +154,7 @@ class Term {
return;
}
control.send(data);
this.control.send(data);
});
this.term.onBinary((data) => {
@@ -161,7 +162,7 @@ class Term {
return;
}
control.sendBinary(data);
this.control.sendBinary(data);
});
this.term.onKey((ev) => {
@@ -169,7 +170,7 @@ class Term {
return;
}
if (!control.echo()) {
if (!this.control.echo()) {
return;
}
@@ -179,13 +180,13 @@ class Term {
!ev.domEvent.ctrlKey &&
!ev.domEvent.metaKey;
switch (ev.domEvent.key.toLowerCase()) {
case "enter":
switch (ev.domEvent.key) {
case "Enter":
ev.domEvent.preventDefault();
this.writeStr("\r\n");
break;
case "backspace":
case "Backspace":
ev.domEvent.preventDefault();
this.writeStr("\b \b");
break;
@@ -198,6 +199,45 @@ class Term {
}
});
this.term.attachCustomKeyEventHandler(async (ev) => {
if (this.closed) {
return true;
}
if (ev.type == "keyup" && (
(ev.key.toLowerCase() === "v" && ev.shiftKey && ev.ctrlKey) ||
(ev.key === "Insert" && ev.shiftKey)
)) {
try {
let text = await window.navigator.clipboard.readText();
this.writeEchoStr(text);
} catch (e) {
alert(
"Unable to paste: " +
e +
". Please try again without using the Control+Shift+V / " +
"Shift+Insert hot key"
);
}
return false;
}
if (ev.type == "keyup" && (
(ev.key.toLowerCase() === "c" && ev.shiftKey && ev.ctrlKey) ||
(ev.key === "Insert" && ev.ctrlKey)
)) {
try {
window.navigator.clipboard.writeText(this.term.getSelection());
} catch (e) {
alert("Unable to copy: " + e);
}
return false;
}
return true;
});
let resizeDelay = null,
oldRows = 0,
oldCols = 0;
@@ -230,7 +270,7 @@ class Term {
return;
}
control.resize({
this.control.resize({
rows: dim.rows,
cols: dim.cols,
});
@@ -248,38 +288,6 @@ class Term {
this.term.textarea.addEventListener("focus", callbacks.focus);
this.term.textarea.addEventListener("blur", callbacks.blur);
this.term.textarea.addEventListener("keyup", async (ev) => {
if (this.closed) {
return;
}
if (ev.ctrlKey && ev.shiftKey) {
switch (ev.keyCode) {
case 86:
try {
let text = await window.navigator.clipboard.readText();
this.writeStr(text);
} catch (e) {
alert(
"Unable to paste: " +
e +
". Please try again without using the Control+Shift+V hot key"
);
}
return;
case 67:
try {
window.navigator.clipboard.writeText(this.term.getSelection());
} catch (e) {
alert("Unable to copy: " + e);
}
return;
}
}
});
this.refit();
}
@@ -295,6 +303,20 @@ class Term {
}
}
writeEchoStr(d) {
if (this.closed) {
return;
}
this.control.send(d);
if (!this.control.echo()) {
return;
}
this.writeStr(d);
}
writeStr(d) {
if (this.closed) {
return;