@@ -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 ;
@@ -737,8 +740,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
737740 this . xterm ?. raw . loadAddon ( this . _quickFixAddon ) ;
738741 this . registerQuickFixProvider ( gitTwoDashes ( ) , freePort ( this ) , gitSimilar ( ) , gitPushSetUpstream ( ) , gitCreatePr ( ) ) ;
739742 this . _register ( this . _quickFixAddon . onDidRequestRerunCommand ( async ( e ) => await this . runCommand ( e . command , e . addNewLine || false ) ) ) ;
740- const lineDataEventAddon = new LineDataEventAddon ( ) ;
741- this . xterm . raw . loadAddon ( lineDataEventAddon ) ;
742743 this . updateAccessibilitySupport ( ) ;
743744 this . xterm . onDidRequestRunCommand ( e => {
744745 if ( e . copyAsHtml ) {
@@ -749,13 +750,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
749750 } ) ;
750751 // Write initial text, deferring onLineFeed listener when applicable to avoid firing
751752 // onLineData events containing initialText
752- if ( this . _shellLaunchConfig . initialText ) {
753- this . _writeInitialText ( this . xterm , ( ) => {
754- lineDataEventAddon . onLineData ( e => this . _onLineData . fire ( e ) ) ;
755- } ) ;
756- } else {
757- lineDataEventAddon . onLineData ( e => this . _onLineData . fire ( e ) ) ;
758- }
753+ const initialTextWrittenPromise = this . _shellLaunchConfig . initialText ? new Promise < void > ( r => this . _writeInitialText ( xterm , r ) ) : undefined ;
754+ const lineDataEventAddon = new LineDataEventAddon ( initialTextWrittenPromise ) ;
755+ lineDataEventAddon . onLineData ( e => this . _onLineData . fire ( e ) ) ;
756+ this . _lineDataEventAddon = lineDataEventAddon ;
759757 // Delay the creation of the bell listener to avoid showing the bell when the terminal
760758 // starts up or reconnects
761759 setTimeout ( ( ) => {
@@ -825,6 +823,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
825823 return xterm ;
826824 }
827825
826+ private async _onLineDataSetup ( ) : Promise < void > {
827+ const xterm = this . xterm || await this . _xtermReadyPromise ;
828+ xterm . raw . loadAddon ( this . _lineDataEventAddon ! ) ;
829+ }
830+
828831 async runCommand ( commandLine : string , addNewLine : boolean ) : Promise < void > {
829832 // Determine whether to send ETX (ctrl+c) before running the command. This should always
830833 // happen unless command detection can reliably say that a command is being entered and
0 commit comments