@@ -127,13 +127,17 @@ interface ShellProps {
127127 */
128128 initialHistory : readonly string [ ] ;
129129
130+ /**
131+ * A boolean so we can keep the isOperationInProgress state between sessions.
132+ */
133+ isOperationInProgress ?: boolean ;
134+
130135 darkMode ?: boolean ;
131136
132137 className ?: string ;
133138}
134139
135140interface ShellState {
136- operationInProgress : boolean ;
137141 output : readonly ShellOutputEntry [ ] ;
138142 history : readonly string [ ] ;
139143 passwordPrompt : string ;
@@ -153,14 +157,6 @@ const normalizeInitialEvaluate = (initialEvaluate: string | string[]) => {
153157 } ) ;
154158} ;
155159
156- const isInitialEvaluateEmpty = (
157- initialEvaluate ?: string | string [ ] | undefined
158- ) => {
159- return (
160- ! initialEvaluate || normalizeInitialEvaluate ( initialEvaluate ) . length === 0
161- ) ;
162- } ;
163-
164160/**
165161 * The browser-repl Shell component
166162 */
@@ -175,6 +171,7 @@ export class _Shell extends Component<ShellProps, ShellState> {
175171 initialInput : '' ,
176172 initialOutput : [ ] ,
177173 initialHistory : [ ] ,
174+ isOperationInProgress : false ,
178175 } ;
179176
180177 private shellInputElement : HTMLElement | null = null ;
@@ -183,7 +180,6 @@ export class _Shell extends Component<ShellProps, ShellState> {
183180 private onCancelPasswordPrompt : ( ) => void = noop ;
184181
185182 readonly state : ShellState = {
186- operationInProgress : ! isInitialEvaluateEmpty ( this . props . initialEvaluate ) ,
187183 output : this . props . initialOutput . slice ( - this . props . maxOutputLength ) ,
188184 history : this . props . initialHistory . slice ( 0 , this . props . maxHistoryLength ) ,
189185 passwordPrompt : '' ,
@@ -357,17 +353,16 @@ export class _Shell extends Component<ShellProps, ShellState> {
357353
358354 let output = this . addEntriesToOutput ( [ inputLine ] ) ;
359355 this . setState ( {
360- operationInProgress : true ,
361356 output,
362357 } ) ;
363358 this . props . onOutputChanged ( output ) ;
364359
360+ // TODO: what if we switch away from the shell while this is ongoing?
365361 const outputLine = await this . evaluate ( code ) ;
366362
367363 output = this . addEntriesToOutput ( [ outputLine ] ) ;
368364 const history = this . addEntryToHistory ( code ) ;
369365 this . setState ( {
370- operationInProgress : false ,
371366 output,
372367 history,
373368 } ) ;
@@ -411,7 +406,7 @@ export class _Shell extends Component<ShellProps, ShellState> {
411406
412407 private onSigInt = ( ) : Promise < boolean > => {
413408 if (
414- this . state . operationInProgress &&
409+ this . props . isOperationInProgress &&
415410 ( this . props . runtime as WorkerRuntime ) . interrupt
416411 ) {
417412 return ( this . props . runtime as WorkerRuntime ) . interrupt ( ) ;
@@ -440,7 +435,7 @@ export class _Shell extends Component<ShellProps, ShellState> {
440435 history = { this . state . history }
441436 onClearCommand = { this . onClearCommand }
442437 onInput = { this . onInput }
443- operationInProgress = { this . state . operationInProgress }
438+ operationInProgress = { this . props . isOperationInProgress }
444439 editorRef = { this . setEditor }
445440 onSigInt = { this . onSigInt }
446441 />
0 commit comments