@@ -91,9 +91,10 @@ export default class CommandWindow implements vscode.Pseudoterminal {
91
91
92
92
private _lastOutputLine : string = '' ;
93
93
94
- private readonly _commandHistory : string [ ] = [ ] ;
94
+ private readonly _rawCommandHistory : string [ ] = [ ] ;
95
95
private _historyIndex : number = 0 ;
96
96
private _lastKnownCurrentLine : string = '' ;
97
+ private _filteredCommandHistory : string [ ] = [ ] ;
97
98
98
99
private _terminalDimensions : vscode . TerminalDimensions ;
99
100
private _lastSentTerminalDimensions : vscode . TerminalDimensions | null = null ;
@@ -346,27 +347,33 @@ export default class CommandWindow implements vscode.Pseudoterminal {
346
347
}
347
348
348
349
private _handleNavigateHistory ( direction : HistoryDirection ) : boolean {
349
- const isCurrentlyAtEndOfHistory = this . _historyIndex === this . _commandHistory . length ;
350
- const isCurrentlyAtBeginningOfHistory = this . _historyIndex === 0 ;
350
+ const isAtEnd = this . _historyIndex === this . _filteredCommandHistory . length ;
351
+ const isAtBeginning = this . _historyIndex === 0 ;
351
352
352
- if ( direction === HistoryDirection . BACKWARDS && isCurrentlyAtBeginningOfHistory ) {
353
+ if ( ( direction === HistoryDirection . BACKWARDS && isAtBeginning ) ||
354
+ ( direction === HistoryDirection . FORWARDS && isAtEnd ) ) {
353
355
return false ;
354
356
}
355
357
356
- if ( direction === HistoryDirection . FORWARDS && isCurrentlyAtEndOfHistory ) {
357
- return false ;
358
- }
359
-
360
- if ( isCurrentlyAtEndOfHistory ) {
358
+ if ( isAtEnd ) {
361
359
this . _lastKnownCurrentLine = this . _stripCurrentPrompt ( this . _currentPromptLine ) ;
362
360
}
363
361
364
362
this . _historyIndex += direction === HistoryDirection . BACKWARDS ? - 1 : 1 ;
365
- return this . _replaceCurrentLineWithNewLine ( this . _currentPrompt + this . _getHistoryItem ( this . _historyIndex ) ) ;
363
+ const line = this . _getHistoryItem ( this . _historyIndex ) ;
364
+ return this . _replaceCurrentLineWithNewLine ( this . _currentPrompt + line ) ;
366
365
}
367
366
368
367
private _markCurrentLineChanged ( ) : void {
369
- this . _historyIndex = this . _commandHistory . length ;
368
+ const commandHistoryFilter = this . _stripCurrentPrompt ( this . _currentPromptLine ) ;
369
+ if ( commandHistoryFilter !== '' ) {
370
+ this . _filteredCommandHistory = this . _rawCommandHistory . filter ( cmd =>
371
+ cmd . toLowerCase ( ) . startsWith ( commandHistoryFilter . toLowerCase ( ) ) ) ;
372
+ } else {
373
+ this . _filteredCommandHistory = this . _rawCommandHistory
374
+ }
375
+
376
+ this . _historyIndex = this . _filteredCommandHistory . length ;
370
377
this . _lastKnownCurrentLine = '' ;
371
378
}
372
379
@@ -582,19 +589,20 @@ export default class CommandWindow implements vscode.Pseudoterminal {
582
589
583
590
private _addToHistory ( command : string ) : void {
584
591
const isEmpty = command === '' ;
585
- const isLastInHistory = this . _commandHistory . length !== 0 && command === this . _commandHistory [ this . _commandHistory . length - 1 ] ;
592
+ const isLastInHistory =
593
+ this . _rawCommandHistory . length !== 0 &&
594
+ command === this . _rawCommandHistory [ this . _rawCommandHistory . length - 1 ] ;
586
595
if ( ! isEmpty && ! isLastInHistory ) {
587
- this . _commandHistory . push ( command ) ;
596
+ this . _rawCommandHistory . push ( command ) ;
588
597
}
589
- this . _historyIndex = this . _commandHistory . length ;
598
+ this . _historyIndex = this . _rawCommandHistory . length ;
599
+ this . _filteredCommandHistory = this . _rawCommandHistory
590
600
}
591
601
592
602
private _getHistoryItem ( n : number ) : string {
593
- if ( this . _historyIndex < this . _commandHistory . length ) {
594
- return this . _commandHistory [ n ] ;
595
- } else {
596
- return this . _lastKnownCurrentLine ;
597
- }
603
+ return ( this . _historyIndex < this . _filteredCommandHistory . length )
604
+ ? this . _filteredCommandHistory [ n ]
605
+ : this . _lastKnownCurrentLine ;
598
606
}
599
607
600
608
private _moveCursorToCurrent ( lineOfInputCursorIsCurrentlyOn ?: number ) : void {
0 commit comments