mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-21 21:32:13 +01:00
fix terminal paste handler -- use paste fn, unify key handlers. add extra if stmts to focusNode calls in block
This commit is contained in:
parent
70ef76be62
commit
c94ff3495b
@ -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
|
||||
|
@ -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<HTMLDivElement>) {
|
||||
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 (
|
||||
<div className={clsx("view-term", "term-mode-" + termMode)} onKeyDown={handleKeyDown} ref={viewRef}>
|
||||
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef}>
|
||||
<TermThemeUpdater blockId={blockId} termRef={termRef} />
|
||||
<TermStickers config={stickerConfig} />
|
||||
<div key="conntectElem" className="term-connectelem" ref={connectElemRef}></div>
|
||||
|
Loading…
Reference in New Issue
Block a user