terminal: focus when repl is requested

This commit is contained in:
David Lechner
2022-10-28 18:01:39 -05:00
committed by David Lechner
parent 03f6c004db
commit 2d9a0ca39e
2 changed files with 16 additions and 1 deletions
+10
View File
@@ -177,6 +177,16 @@ const Terminal: React.FC = (_props) => {
[createContextMenu, xterm],
);
useEffect(() => {
const listener = () => {
xterm.focus();
};
addEventListener('pb-terminal-focus', listener);
return () => removeEventListener('pb-terminal-focus', listener);
}, [xterm]);
return (
<ContextMenu2
className="h-100"
+6 -1
View File
@@ -20,7 +20,7 @@ import {
write,
} from '../ble-nordic-uart-service/actions';
import { nordicUartSafeTxCharLength } from '../ble-nordic-uart-service/protocol';
import { checksum } from '../hub/actions';
import { checksum, repl } from '../hub/actions';
import { HubRuntimeState } from '../hub/reducers';
import { RootState } from '../reducers';
import { defined } from '../utils';
@@ -94,8 +94,13 @@ function* sendTerminalData(action: ReturnType<typeof sendData>): Generator {
dataSource.next(action.value);
}
function handleRepl(): void {
dispatchEvent(new CustomEvent('pb-terminal-focus'));
}
export default function* (): Generator {
yield* takeEvery(didNotify, receiveUartData);
yield* fork(receiveTerminalData);
yield* takeEvery(sendData, sendTerminalData);
yield* takeEvery(repl, handleRepl);
}