@@ -524,9 +524,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
524524 throw new Error ( 'The terminal instance has not been attached to a container yet' ) ;
525525 }
526526
527- if ( this . _wrapperElement . parentNode ) {
528- this . _wrapperElement . parentNode . removeChild ( this . _wrapperElement ) ;
529- }
527+ this . _wrapperElement . parentNode ?. removeChild ( this . _wrapperElement ) ;
530528 this . _container = container ;
531529 this . _container . appendChild ( this . _wrapperElement ) ;
532530 }
@@ -544,9 +542,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
544542 }
545543
546544 // The container changed, reattach
547- if ( this . _container ) {
548- this . _container . removeChild ( this . _wrapperElement ) ;
549- }
545+ this . _container ?. removeChild ( this . _wrapperElement ) ;
550546 this . _container = container ;
551547 this . _container . appendChild ( this . _wrapperElement ) ;
552548 }
@@ -652,11 +648,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
652648
653649 const widgetManager = new TerminalWidgetManager ( this . _wrapperElement ) ;
654650 this . _widgetManager = widgetManager ;
655- this . _processManager . onProcessReady ( ( ) => {
656- if ( this . _linkHandler ) {
657- this . _linkHandler . setWidgetManager ( widgetManager ) ;
658- }
659- } ) ;
651+ this . _processManager . onProcessReady ( ( ) => this . _linkHandler ?. setWidgetManager ( widgetManager ) ) ;
660652
661653 const computedStyle = window . getComputedStyle ( this . _container ) ;
662654 const width = parseInt ( computedStyle . getPropertyValue ( 'width' ) . replace ( 'px' , '' ) , 10 ) ;
@@ -751,19 +743,13 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
751743 }
752744
753745 public clearSelection ( ) : void {
754- if ( ! this . _xterm ) {
755- return ;
756- }
757- this . _xterm . clearSelection ( ) ;
746+ this . _xterm ?. clearSelection ( ) ;
758747 }
759748
760749 public selectAll ( ) : void {
761- if ( ! this . _xterm ) {
762- return ;
763- }
764750 // Focus here to ensure the terminal context key is set
765- this . _xterm . focus ( ) ;
766- this . _xterm . selectAll ( ) ;
751+ this . _xterm ? .focus ( ) ;
752+ this . _xterm ? .selectAll ( ) ;
767753 }
768754
769755 public findNext ( term : string , searchOptions : ISearchOptions ) : boolean {
@@ -924,45 +910,31 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
924910 }
925911
926912 public scrollDownLine ( ) : void {
927- if ( this . _xterm ) {
928- this . _xterm . scrollLines ( 1 ) ;
929- }
913+ this . _xterm ?. scrollLines ( 1 ) ;
930914 }
931915
932916 public scrollDownPage ( ) : void {
933- if ( this . _xterm ) {
934- this . _xterm . scrollPages ( 1 ) ;
935- }
917+ this . _xterm ?. scrollPages ( 1 ) ;
936918 }
937919
938920 public scrollToBottom ( ) : void {
939- if ( this . _xterm ) {
940- this . _xterm . scrollToBottom ( ) ;
941- }
921+ this . _xterm ?. scrollToBottom ( ) ;
942922 }
943923
944924 public scrollUpLine ( ) : void {
945- if ( this . _xterm ) {
946- this . _xterm . scrollLines ( - 1 ) ;
947- }
925+ this . _xterm ?. scrollLines ( - 1 ) ;
948926 }
949927
950928 public scrollUpPage ( ) : void {
951- if ( this . _xterm ) {
952- this . _xterm . scrollPages ( - 1 ) ;
953- }
929+ this . _xterm ?. scrollPages ( - 1 ) ;
954930 }
955931
956932 public scrollToTop ( ) : void {
957- if ( this . _xterm ) {
958- this . _xterm . scrollToTop ( ) ;
959- }
933+ this . _xterm ?. scrollToTop ( ) ;
960934 }
961935
962936 public clear ( ) : void {
963- if ( this . _xterm ) {
964- this . _xterm . clear ( ) ;
965- }
937+ this . _xterm ?. clear ( ) ;
966938 }
967939
968940 private _refreshSelectionContextKey ( ) {
@@ -1019,12 +991,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
1019991 }
1020992
1021993 private _onProcessData ( data : string ) : void {
1022- if ( this . _widgetManager ) {
1023- this . _widgetManager . closeMessage ( ) ;
1024- }
1025- if ( this . _xterm ) {
1026- this . _xterm . write ( data ) ;
1027- }
994+ this . _widgetManager ?. closeMessage ( ) ;
995+ this . _xterm ?. write ( data ) ;
1028996 }
1029997
1030998 /**
@@ -1130,10 +1098,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
11301098
11311099 public reuseTerminal ( shell : IShellLaunchConfig ) : void {
11321100 // Unsubscribe any key listener we may have.
1133- if ( this . _pressAnyKeyToCloseListener ) {
1134- this . _pressAnyKeyToCloseListener . dispose ( ) ;
1135- this . _pressAnyKeyToCloseListener = undefined ;
1136- }
1101+ this . _pressAnyKeyToCloseListener ?. dispose ( ) ;
1102+ this . _pressAnyKeyToCloseListener = undefined ;
11371103
11381104 // Kill and clear up the process, making the process manager ready for a new process
11391105 this . _processManager . dispose ( ) ;
@@ -1256,10 +1222,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
12561222 this . _navigationModeAddon = new NavigationModeAddon ( this . _terminalA11yTreeFocusContextKey ) ;
12571223 this . _xterm ! . loadAddon ( this . _navigationModeAddon ) ;
12581224 } else {
1259- if ( this . _navigationModeAddon ) {
1260- this . _navigationModeAddon . dispose ( ) ;
1261- this . _navigationModeAddon = undefined ;
1262- }
1225+ this . _navigationModeAddon ?. dispose ( ) ;
1226+ this . _navigationModeAddon = undefined ;
12631227 }
12641228 this . _xterm ! . setOption ( 'screenReaderMode' , isEnabled ) ;
12651229 }
0 commit comments