@@ -7,12 +7,14 @@ import { SimpleFindWidget } from 'vs/workbench/contrib/codeEditor/browser/find/s
77import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
88import { IContextKeyService , IContextKey } from 'vs/platform/contextkey/common/contextkey' ;
99import { FindReplaceState } from 'vs/editor/contrib/find/browser/findState' ;
10- import { ITerminalGroupService , ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal' ;
10+ import { ITerminalGroupService , ITerminalService , IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal' ;
1111import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey' ;
1212import { TerminalLocation } from 'vs/platform/terminal/common/terminal' ;
1313import { IThemeService } from 'vs/platform/theme/common/themeService' ;
1414import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1515import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
16+ import { Event } from 'vs/base/common/event' ;
17+ import { ISearchOptions } from 'xterm-addon-search' ;
1618
1719export class TerminalFindWidget extends SimpleFindWidget {
1820 protected _findInputFocused : IContextKey < boolean > ;
@@ -50,23 +52,24 @@ export class TerminalFindWidget extends SimpleFindWidget {
5052 }
5153
5254 find ( previous : boolean , update ?: boolean ) {
53- const instance = this . _terminalService . activeInstance ;
54- if ( ! instance ) {
55+ const xterm = this . _terminalService . activeInstance ?. xterm ;
56+ if ( ! xterm ) {
5557 return ;
5658 }
5759 if ( previous ) {
58- instance . xterm ?. findPrevious ( this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) , incremental : update } ) ;
60+ this . _findPreviousWithEvent ( xterm , this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) , incremental : update } ) ;
5961 } else {
60- instance . xterm ?. findNext ( this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) } ) ;
62+ this . _findNextWithEvent ( xterm , this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) } ) ;
6163 }
6264 }
6365
6466 override reveal ( initialInput ?: string ) : void {
65- const instance = this . _terminalService . activeInstance ;
66- if ( instance && this . inputValue && this . inputValue !== '' ) {
67+ const xterm = this . _terminalService . activeInstance ?. xterm ;
68+ if ( xterm && this . inputValue && this . inputValue !== '' ) {
6769 // trigger highlight all matches
68- instance . xterm ?. findPrevious ( this . inputValue , { incremental : true , regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) } ) . then ( foundMatch => {
70+ this . _findPreviousWithEvent ( xterm , this . inputValue , { incremental : true , regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) } ) . then ( foundMatch => {
6971 this . updateButtons ( foundMatch ) ;
72+ this . _register ( Event . once ( xterm . onDidChangeSelection ) ( ( ) => xterm . clearActiveSearchDecoration ( ) ) ) ;
7073 } ) ;
7174 }
7275 this . updateButtons ( false ) ;
@@ -109,9 +112,9 @@ export class TerminalFindWidget extends SimpleFindWidget {
109112
110113 protected _onInputChanged ( ) {
111114 // Ignore input changes for now
112- const instance = this . _terminalService . activeInstance ;
113- if ( instance ?. xterm ) {
114- instance . xterm . findPrevious ( this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) , incremental : true } ) . then ( foundMatch => {
115+ const xterm = this . _terminalService . activeInstance ?. xterm ;
116+ if ( xterm ) {
117+ this . _findPreviousWithEvent ( xterm , this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) , incremental : true } ) . then ( foundMatch => {
115118 this . updateButtons ( foundMatch ) ;
116119 } ) ;
117120 }
@@ -130,6 +133,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
130133 const instance = this . _terminalService . activeInstance ;
131134 if ( instance ) {
132135 instance . notifyFindWidgetFocusChanged ( false ) ;
136+ instance . xterm ?. clearActiveSearchDecoration ( ) ;
133137 }
134138 this . _findWidgetFocused . reset ( ) ;
135139 }
@@ -148,7 +152,24 @@ export class TerminalFindWidget extends SimpleFindWidget {
148152 if ( instance . hasSelection ( ) ) {
149153 instance . clearSelection ( ) ;
150154 }
151- instance . xterm ?. findPrevious ( this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) } ) ;
155+ const xterm = instance . xterm ;
156+ if ( xterm ) {
157+ this . _findPreviousWithEvent ( xterm , this . inputValue , { regex : this . _getRegexValue ( ) , wholeWord : this . _getWholeWordValue ( ) , caseSensitive : this . _getCaseSensitiveValue ( ) } ) ;
158+ }
152159 }
153160 }
161+
162+ private async _findNextWithEvent ( xterm : IXtermTerminal , term : string , options : ISearchOptions ) : Promise < boolean > {
163+ return xterm . findNext ( term , options ) . then ( foundMatch => {
164+ this . _register ( Event . once ( xterm . onDidChangeSelection ) ( ( ) => xterm . clearActiveSearchDecoration ( ) ) ) ;
165+ return foundMatch ;
166+ } ) ;
167+ }
168+
169+ private async _findPreviousWithEvent ( xterm : IXtermTerminal , term : string , options : ISearchOptions ) : Promise < boolean > {
170+ return xterm . findPrevious ( term , options ) . then ( foundMatch => {
171+ this . _register ( Event . once ( xterm . onDidChangeSelection ) ( ( ) => xterm . clearActiveSearchDecoration ( ) ) ) ;
172+ return foundMatch ;
173+ } ) ;
174+ }
154175}
0 commit comments