From bd2bb5293f517c46d304c5bd89b98bd7349e0436 Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 24 Jun 2024 17:58:40 -0700 Subject: [PATCH] enable copy/paste via Cmd:Shift:C and Cmd:Shift:V in the terminal --- frontend/app/tab/tab.tsx | 2 ++ frontend/app/view/term/term.tsx | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/frontend/app/tab/tab.tsx b/frontend/app/tab/tab.tsx index aa3eccebc..0f243c426 100644 --- a/frontend/app/tab/tab.tsx +++ b/frontend/app/tab/tab.tsx @@ -110,6 +110,8 @@ const Tab = forwardRef( function handleContextMenu(e: React.MouseEvent) { e.preventDefault(); let menu: ContextMenuItem[] = []; + menu.push({ label: "Copy TabId", click: () => navigator.clipboard.writeText(id) }); + menu.push({ type: "separator" }); menu.push({ label: "Close Tab", click: () => onClose(null) }); ContextMenuModel.showContextMenu(menu, e); } diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 337f0f664..a3de76975 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -282,8 +282,28 @@ const TerminalView = ({ blockId }: { blockId: string }) => { blockId: blockId, }; + function handleKeyDown(e: React.KeyboardEvent) { + 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 ( -
+