enable copy/paste via Cmd:Shift:C and Cmd:Shift:V in the terminal

This commit is contained in:
sawka
2024-06-24 17:58:40 -07:00
parent b2e12e4171
commit bd2bb5293f
2 changed files with 23 additions and 1 deletions
+21 -1
View File
@@ -282,8 +282,28 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
blockId: blockId,
};
function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
e.preventDefault();
e.stopPropagation();
const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(e);
if (keyutil.checkKeyPressed(waveEvent, "Cmd:Shift:v")) {
const p = navigator.clipboard.readText();
p.then((text) => {
termRef.current?.handleTermData(text);
});
return true;
} else if (keyutil.checkKeyPressed(waveEvent, "Cmd:Shift:c")) {
const sel = termRef.current?.terminal.getSelection();
navigator.clipboard.writeText(sel);
return true;
}
}
return (
<div className={clsx("view-term", "term-mode-" + termMode, isFocused ? "is-focused" : null)}>
<div
className={clsx("view-term", "term-mode-" + termMode, isFocused ? "is-focused" : null)}
onKeyDown={handleKeyDown}
>
<TermStickers config={stickerConfig} />
<div key="conntectElem" className="term-connectelem" ref={connectElemRef}></div>
<div