UI: Ensure prompts shown by ns.prompt do not lose focus in the terminal tab (#2631)

This commit is contained in:
catloversg
2026-04-05 06:39:06 +07:00
committed by GitHub
parent eb4e193fac
commit 996bb01075
4 changed files with 14 additions and 1 deletions

View File

@@ -100,3 +100,9 @@ with a semicolon (;). For example:
$ run foo.js; tail foo.js
Chained commands do **not** wait for functions like `hack` or `wget` to finish executing, and so may not always work as expected.
## Quirks
When your scripts render a text box (e.g., `<input>`, `<textarea>`) with the `autoFocus` attribute in the terminal or
the tail log window, it may not focus automatically as expected. To be precise, the text box receives focus, but the
terminal may immediately reclaim it. This depends on the specific timing of the render.

View File

@@ -149,6 +149,8 @@ export class Terminal {
// True if a Coding Contract prompt is opened
contractOpen = false;
// True if a prompt is opened via the ns.prompt() API
nsPromptApiOpen = false;
// Path of current directory
currDir = "" as Directory;

View File

@@ -209,7 +209,9 @@ export function TerminalInput(): React.ReactElement {
// Catch all key inputs and redirect them to the terminal.
useEffect(() => {
function keyDown(this: Document, event: KeyboardEvent): void {
if (Terminal.contractOpen) return;
if (Terminal.contractOpen || Terminal.nsPromptApiOpen) {
return;
}
if (Terminal.action !== null && event.key === KEY.C && event.ctrlKey) {
Terminal.finishAction(true);
return;

View File

@@ -7,6 +7,7 @@ import Select, { SelectChangeEvent } from "@mui/material/Select";
import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import { KEY } from "../../utils/KeyboardEventKey";
import { Terminal } from "../../Terminal";
export const PromptEvent = new EventEmitter<[Prompt]>();
@@ -60,6 +61,8 @@ export function PromptManager({ hidden }: { hidden: boolean }): React.ReactEleme
setPrompt(null);
};
Terminal.nsPromptApiOpen = !hidden && prompt !== null;
return (
<Modal open={!hidden && prompt !== null} onClose={close}>
{prompt && (