@@ -210,6 +210,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
210210 private _usedShellIntegrationInjection : boolean = false ;
211211 get usedShellIntegrationInjection ( ) : boolean { return this . _usedShellIntegrationInjection ; }
212212 private _quickFixAddon : TerminalQuickFixAddon | undefined ;
213+ private _lineDataEventAddon : LineDataEventAddon | undefined ;
213214
214215 readonly capabilities = new TerminalCapabilityStoreMultiplexer ( ) ;
215216 readonly statusList : ITerminalStatusList ;
@@ -337,7 +338,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
337338 readonly onData = this . _onData . event ;
338339 private readonly _onBinary = this . _register ( new Emitter < string > ( ) ) ;
339340 readonly onBinary = this . _onBinary . event ;
340- private readonly _onLineData = this . _register ( new Emitter < string > ( ) ) ;
341+ private readonly _onLineData = this . _register ( new Emitter < string > ( {
342+ onDidAddFirstListener : ( ) => this . _onLineDataSetup ( )
343+ } ) ) ;
341344 readonly onLineData = this . _onLineData . event ;
342345 private readonly _onRequestExtHostProcess = this . _register ( new Emitter < ITerminalInstance > ( ) ) ;
343346 readonly onRequestExtHostProcess = this . _onRequestExtHostProcess . event ;
@@ -734,8 +737,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
734737 this . xterm ?. raw . loadAddon ( this . _quickFixAddon ) ;
735738 this . registerQuickFixProvider ( gitTwoDashes ( ) , freePort ( this ) , gitSimilar ( ) , gitPushSetUpstream ( ) , gitCreatePr ( ) ) ;
736739 this . _register ( this . _quickFixAddon . onDidRequestRerunCommand ( async ( e ) => await this . runCommand ( e . command , e . addNewLine || false ) ) ) ;
737- const lineDataEventAddon = new LineDataEventAddon ( ) ;
738- this . xterm . raw . loadAddon ( lineDataEventAddon ) ;
739740 this . updateAccessibilitySupport ( ) ;
740741 this . xterm . onDidRequestRunCommand ( e => {
741742 if ( e . copyAsHtml ) {
@@ -746,13 +747,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
746747 } ) ;
747748 // Write initial text, deferring onLineFeed listener when applicable to avoid firing
748749 // onLineData events containing initialText
749- if ( this . _shellLaunchConfig . initialText ) {
750- this . _writeInitialText ( this . xterm , ( ) => {
751- lineDataEventAddon . onLineData ( e => this . _onLineData . fire ( e ) ) ;
752- } ) ;
753- } else {
754- lineDataEventAddon . onLineData ( e => this . _onLineData . fire ( e ) ) ;
755- }
750+ const initialTextWrittenPromise = this . _shellLaunchConfig . initialText ? new Promise < void > ( r => this . _writeInitialText ( xterm , r ) ) : undefined ;
751+ const lineDataEventAddon = new LineDataEventAddon ( initialTextWrittenPromise ) ;
752+ lineDataEventAddon . onLineData ( e => this . _onLineData . fire ( e ) ) ;
753+ this . _lineDataEventAddon = lineDataEventAddon ;
756754 // Delay the creation of the bell listener to avoid showing the bell when the terminal
757755 // starts up or reconnects
758756 setTimeout ( ( ) => {
@@ -822,6 +820,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
822820 return xterm ;
823821 }
824822
823+ private async _onLineDataSetup ( ) : Promise < void > {
824+ const xterm = this . xterm || await this . _xtermReadyPromise ;
825+ xterm . raw . loadAddon ( this . _lineDataEventAddon ! ) ;
826+ }
827+
825828 async runCommand ( commandLine : string , addNewLine : boolean ) : Promise < void > {
826829 // Determine whether to send ETX (ctrl+c) before running the command. This should always
827830 // happen unless command detection can reliably say that a command is being entered and
0 commit comments