@@ -210,6 +210,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
210
210
private _usedShellIntegrationInjection : boolean = false ;
211
211
get usedShellIntegrationInjection ( ) : boolean { return this . _usedShellIntegrationInjection ; }
212
212
private _quickFixAddon : TerminalQuickFixAddon | undefined ;
213
+ private _lineDataEventAddon : LineDataEventAddon | undefined ;
213
214
214
215
readonly capabilities = new TerminalCapabilityStoreMultiplexer ( ) ;
215
216
readonly statusList : ITerminalStatusList ;
@@ -337,7 +338,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
337
338
readonly onData = this . _onData . event ;
338
339
private readonly _onBinary = this . _register ( new Emitter < string > ( ) ) ;
339
340
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
+ } ) ) ;
341
344
readonly onLineData = this . _onLineData . event ;
342
345
private readonly _onRequestExtHostProcess = this . _register ( new Emitter < ITerminalInstance > ( ) ) ;
343
346
readonly onRequestExtHostProcess = this . _onRequestExtHostProcess . event ;
@@ -734,8 +737,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
734
737
this . xterm ?. raw . loadAddon ( this . _quickFixAddon ) ;
735
738
this . registerQuickFixProvider ( gitTwoDashes ( ) , freePort ( this ) , gitSimilar ( ) , gitPushSetUpstream ( ) , gitCreatePr ( ) ) ;
736
739
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 ) ;
739
740
this . updateAccessibilitySupport ( ) ;
740
741
this . xterm . onDidRequestRunCommand ( e => {
741
742
if ( e . copyAsHtml ) {
@@ -746,13 +747,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
746
747
} ) ;
747
748
// Write initial text, deferring onLineFeed listener when applicable to avoid firing
748
749
// 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 ;
756
754
// Delay the creation of the bell listener to avoid showing the bell when the terminal
757
755
// starts up or reconnects
758
756
setTimeout ( ( ) => {
@@ -822,6 +820,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
822
820
return xterm ;
823
821
}
824
822
823
+ private async _onLineDataSetup ( ) : Promise < void > {
824
+ const xterm = this . xterm || await this . _xtermReadyPromise ;
825
+ xterm . raw . loadAddon ( this . _lineDataEventAddon ! ) ;
826
+ }
827
+
825
828
async runCommand ( commandLine : string , addNewLine : boolean ) : Promise < void > {
826
829
// Determine whether to send ETX (ctrl+c) before running the command. This should always
827
830
// happen unless command detection can reliably say that a command is being entered and
0 commit comments