@@ -421,6 +421,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
421421
422422 @memoize
423423 private get refreshScheduler ( ) : RunOnceScheduler {
424+ const autoExpanded = new Set < string > ( ) ;
424425 return new RunOnceScheduler ( async ( ) => {
425426 if ( ! this . tree . getInput ( ) ) {
426427 return ;
@@ -431,11 +432,22 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
431432
432433 const session = this . tree . getInput ( ) ;
433434 if ( session ) {
434- const replElements = session . getReplElements ( ) ;
435- const lastElement = replElements . length ? replElements [ replElements . length - 1 ] : undefined ;
436- if ( lastElement instanceof ReplGroup && lastElement . autoExpand ) {
437- await this . tree . expand ( lastElement ) ;
438- }
435+ // Automatically expand repl group elements when specified
436+ const autoExpandElements = async ( elements : IReplElement [ ] ) => {
437+ for ( let element of elements ) {
438+ if ( element instanceof ReplGroup ) {
439+ if ( element . autoExpand && ! autoExpanded . has ( element . getId ( ) ) ) {
440+ autoExpanded . add ( element . getId ( ) ) ;
441+ await this . tree . expand ( element ) ;
442+ }
443+ if ( ! this . tree . isCollapsed ( element ) ) {
444+ // Repl groups can have children which are repl groups thus we might need to expand those as well
445+ await autoExpandElements ( element . getChildren ( ) ) ;
446+ }
447+ }
448+ }
449+ } ;
450+ await autoExpandElements ( session . getReplElements ( ) ) ;
439451 }
440452
441453 if ( lastElementVisible ) {
0 commit comments