From c94ff3495bfb011d1a641dc13e330fbfe78927d1 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 3 Sep 2024 00:02:03 -0700 Subject: [PATCH] fix terminal paste handler -- use paste fn, unify key handlers. add extra if stmts to focusNode calls in block --- frontend/app/block/block.tsx | 8 ++++-- frontend/app/view/term/term.tsx | 48 ++++++++++++++------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/frontend/app/block/block.tsx b/frontend/app/block/block.tsx index 8c08ecba1..3f155e0e7 100644 --- a/frontend/app/block/block.tsx +++ b/frontend/app/block/block.tsx @@ -151,14 +151,18 @@ const BlockFull = React.memo(({ nodeModel, viewModel }: FullBlockProps) => { if (!focusWithin) { setFocusTarget(); } - nodeModel.focusNode(); + if (!isFocused) { + nodeModel.focusNode(); + } }, [blockClicked]); React.useLayoutEffect(() => { if (focusedChild == null) { return; } - nodeModel.focusNode(); + if (!isFocused) { + nodeModel.focusNode(); + } }, [focusedChild]); // treat the block as clicked on creation diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index ddf3f6517..847c5dc0d 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -214,6 +214,9 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { React.useEffect(() => { function handleTerminalKeydown(event: KeyboardEvent): boolean { const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(event); + if (waveEvent.type != "keydown") { + return true; + } if (keyutil.checkKeyPressed(waveEvent, "Cmd:Escape")) { event.preventDefault(); event.stopPropagation(); @@ -236,6 +239,22 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { return false; } } + if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:v")) { + const p = navigator.clipboard.readText(); + p.then((text) => { + termRef.current?.terminal.paste(text); + // termRef.current?.handleTermData(text); + }); + event.preventDefault(); + event.stopPropagation(); + return true; + } else if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:c")) { + const sel = termRef.current?.terminal.getSelection(); + navigator.clipboard.writeText(sel); + event.preventDefault(); + event.stopPropagation(); + return true; + } if (shellProcStatusRef.current != "running" && keyutil.checkKeyPressed(waveEvent, "Enter")) { // restart WshServer.ControllerRestartCommand({ blockid: blockId }); @@ -331,35 +350,8 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => { blockId: blockId, }; - function handleKeyDown(e: React.KeyboardEvent) { - const waveEvent = keyutil.adaptFromReactOrNativeKeyEvent(e); - if (keyutil.checkKeyPressed(waveEvent, "Cmd:Shift:v")) { - const p = navigator.clipboard.readText(); - p.then((text) => { - termRef.current?.handleTermData(text); - }); - e.preventDefault(); - e.stopPropagation(); - return true; - } else if (keyutil.checkKeyPressed(waveEvent, "Cmd:Shift:c")) { - const sel = termRef.current?.terminal.getSelection(); - navigator.clipboard.writeText(sel); - e.preventDefault(); - e.stopPropagation(); - return true; - } - } - - const changeConnection = React.useCallback( - async (connName: string) => { - await WshServer.SetMetaCommand({ oref: WOS.makeORef("block", blockId), meta: { connection: connName } }); - await WshServer.ControllerRestartCommand({ blockid: blockId }); - }, - [blockId] - ); - return ( -
+