mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
UI: Ensure prompts shown by ns.prompt do not lose focus in the terminal tab (#2631)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 && (
|
||||
|
||||
Reference in New Issue
Block a user