@@ -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 ;
@@ -737,8 +740,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
737
740
this . xterm ?. raw . loadAddon ( this . _quickFixAddon ) ;
738
741
this . registerQuickFixProvider ( gitTwoDashes ( ) , freePort ( this ) , gitSimilar ( ) , gitPushSetUpstream ( ) , gitCreatePr ( ) ) ;
739
742
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 ) ;
742
743
this . updateAccessibilitySupport ( ) ;
743
744
this . xterm . onDidRequestRunCommand ( e => {
744
745
if ( e . copyAsHtml ) {
@@ -749,13 +750,10 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
749
750
} ) ;
750
751
// Write initial text, deferring onLineFeed listener when applicable to avoid firing
751
752
// 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 ;
759
757
// Delay the creation of the bell listener to avoid showing the bell when the terminal
760
758
// starts up or reconnects
761
759
setTimeout ( ( ) => {
@@ -825,6 +823,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
825
823
return xterm ;
826
824
}
827
825
826
+ private async _onLineDataSetup ( ) : Promise < void > {
827
+ const xterm = this . xterm || await this . _xtermReadyPromise ;
828
+ xterm . raw . loadAddon ( this . _lineDataEventAddon ! ) ;
829
+ }
830
+
828
831
async runCommand ( commandLine : string , addNewLine : boolean ) : Promise < void > {
829
832
// Determine whether to send ETX (ctrl+c) before running the command. This should always
830
833
// happen unless command detection can reliably say that a command is being entered and
0 commit comments