@@ -171,7 +171,7 @@ export class CommandDetectionCapability extends Disposable implements ICommandDe
171
171
get isCommandStorageDisabled ( ) { return that . __isCommandStorageDisabled ; }
172
172
get commandMarkers ( ) { return that . _commandMarkers ; }
173
173
set commandMarkers ( value ) { that . _commandMarkers = value ; }
174
- get clearCommandsInViewport ( ) { return that . _clearCommandsInViewport ; }
174
+ get clearCommandsInViewport ( ) { return that . _clearCommandsInViewport . bind ( that ) ; }
175
175
} ,
176
176
this . _logService
177
177
) ;
@@ -504,7 +504,8 @@ const enum AdjustCommandStartMarkerConstants {
504
504
class WindowsPtyHeuristics extends Disposable {
505
505
506
506
private _onCursorMoveListener = this . _register ( new MutableDisposable ( ) ) ;
507
- private _windowsPromptPollingInProcess : boolean = false ;
507
+
508
+ private _recentlyPerformedCsiJ = false ;
508
509
509
510
constructor (
510
511
private readonly _terminal : Terminal ,
@@ -514,11 +515,27 @@ class WindowsPtyHeuristics extends Disposable {
514
515
) {
515
516
super ( ) ;
516
517
518
+ this . _register ( _terminal . parser . registerCsiHandler ( { final : 'J' } , params => {
519
+ if ( params . length >= 1 && ( params [ 0 ] === 2 || params [ 0 ] === 3 ) ) {
520
+ this . _recentlyPerformedCsiJ = true ;
521
+ this . _hooks . clearCommandsInViewport ( ) ;
522
+ }
523
+ // We don't want to override xterm.js' default behavior, just augment it
524
+ return false ;
525
+ } ) ) ;
526
+
517
527
this . _register ( this . _capability . onBeforeCommandFinished ( command => {
518
- // For a Windows backend we cannot listen to CSI J, instead we assume running clear or
519
- // cls will clear all commands in the viewport. This is not perfect but it's right most
520
- // of the time.
528
+ if ( this . _recentlyPerformedCsiJ ) {
529
+ this . _recentlyPerformedCsiJ = false ;
530
+ return ;
531
+ }
532
+
533
+ // For older Windows backends we cannot listen to CSI J, instead we assume running clear
534
+ // or cls will clear all commands in the viewport. This is not perfect but it's right
535
+ // most of the time.
521
536
if ( command . command . trim ( ) . toLowerCase ( ) === 'clear' || command . command . trim ( ) . toLowerCase ( ) === 'cls' ) {
537
+ this . _tryAdjustCommandStartMarkerScheduler ?. cancel ( ) ;
538
+ this . _tryAdjustCommandStartMarkerScheduler = undefined ;
522
539
this . _hooks . clearCommandsInViewport ( ) ;
523
540
this . _capability . currentCommand . isInvalid = true ;
524
541
this . _hooks . onCurrentCommandInvalidatedEmitter . fire ( { reason : CommandInvalidationReason . Windows } ) ;
@@ -580,10 +597,6 @@ class WindowsPtyHeuristics extends Disposable {
580
597
private _tryAdjustCommandStartMarkerPollCount : number = 0 ;
581
598
582
599
async handleCommandStart ( ) {
583
-
584
- if ( this . _windowsPromptPollingInProcess ) {
585
- this . _windowsPromptPollingInProcess = false ;
586
- }
587
600
this . _capability . currentCommand . commandStartX = this . _terminal . buffer . active . cursorX ;
588
601
589
602
// On Windows track all cursor movements after the command start sequence
0 commit comments