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

View File

@ -110,6 +110,8 @@ const Tab = forwardRef<HTMLDivElement, TabProps>(
function handleContextMenu(e: React.MouseEvent<HTMLDivElement, MouseEvent>) { function handleContextMenu(e: React.MouseEvent<HTMLDivElement, MouseEvent>) {
e.preventDefault(); e.preventDefault();
let menu: ContextMenuItem[] = []; 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) }); menu.push({ label: "Close Tab", click: () => onClose(null) });
ContextMenuModel.showContextMenu(menu, e); ContextMenuModel.showContextMenu(menu, e);
} }

View File

@ -282,8 +282,28 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
blockId: blockId, 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 ( 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} /> <TermStickers config={stickerConfig} />
<div key="conntectElem" className="term-connectelem" ref={connectElemRef}></div> <div key="conntectElem" className="term-connectelem" ref={connectElemRef}></div>
<div <div