1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { SimpleFindWidget } from 'vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { FindReplaceState } from 'vs/editor/contrib/find/browser/findState';
import { ITerminalGroupService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
import { TerminalLocation } from 'vs/platform/terminal/common/terminal';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
export class TerminalFindWidget extends SimpleFindWidget {
protected _findInputFocused: IContextKey<boolean>;
protected _findWidgetFocused: IContextKey<boolean>;
private _findWidgetVisible: IContextKey<boolean>;
constructor(
findState: FindReplaceState,
@IContextViewService _contextViewService: IContextViewService,
@IKeybindingService keybindingService: IKeybindingService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@ITerminalService private readonly _terminalService: ITerminalService,
@ITerminalGroupService private readonly _terminalGroupService: ITerminalGroupService,
@IThemeService private readonly _themeService: IThemeService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super(findState, { showOptionButtons: true, showResultCount: true, type: 'Terminal' }, _contextViewService, _contextKeyService, keybindingService);
this._register(findState.onFindReplaceStateChange(() => {
this.show();
}));
this._findInputFocused = TerminalContextKeys.findInputFocus.bindTo(this._contextKeyService);
this._findWidgetFocused = TerminalContextKeys.findFocus.bindTo(this._contextKeyService);
this._findWidgetVisible = TerminalContextKeys.findVisible.bindTo(_contextKeyService);
this._register(this._themeService.onDidColorThemeChange(() => {
if (this._findWidgetVisible) {
this.find(true, true);
}
}));
this._register(this._configurationService.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('workbench.colorCustomizations') && this._findWidgetVisible) {
this.find(true, true);
}
}));
}
find(previous: boolean, update?: boolean) {
const instance = this._terminalService.activeInstance;
if (!instance) {
return;
}
if (previous) {
instance.xterm?.findPrevious(this.inputValue, { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue(), incremental: update });
} else {
instance.xterm?.findNext(this.inputValue, { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue() });
}
}
override reveal(initialInput?: string): void {
const instance = this._terminalService.activeInstance;
if (instance && this.inputValue && this.inputValue !== '') {
// trigger highlight all matches
instance.xterm?.findPrevious(this.inputValue, { incremental: true, regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue() }).then(foundMatch => {
this.updateButtons(foundMatch);
});
}
this.updateButtons(false);
super.reveal(initialInput);
this._findWidgetVisible.set(true);
}
override show(initialInput?: string) {
super.show(initialInput);
this._findWidgetVisible.set(true);
}
override hide() {
super.hide();
this._findWidgetVisible.reset();
const instance = this._terminalService.activeInstance;
if (instance) {
instance.focus();
}
// Terminals in a group currently share a find widget, so hide
// all decorations for terminals in this group
const activeGroup = this._terminalGroupService.activeGroup;
if (instance?.target !== TerminalLocation.Editor && activeGroup) {
for (const terminal of activeGroup.terminalInstances) {
terminal.xterm?.clearSearchDecorations();
}
} else {
instance?.xterm?.clearSearchDecorations();
}
}
protected async _getResultCount(): Promise<{ resultIndex: number; resultCount: number } | undefined> {
const instance = this._terminalService.activeInstance;
if (instance) {
return instance.xterm?.findResult;
}
return undefined;
}
protected _onInputChanged() {
// Ignore input changes for now
const instance = this._terminalService.activeInstance;
if (instance?.xterm) {
instance.xterm.findPrevious(this.inputValue, { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue(), incremental: true }).then(foundMatch => {
this.updateButtons(foundMatch);
});
}
return false;
}
protected _onFocusTrackerFocus() {
const instance = this._terminalService.activeInstance;
if (instance) {
instance.notifyFindWidgetFocusChanged(true);
}
this._findWidgetFocused.set(true);
}
protected _onFocusTrackerBlur() {
const instance = this._terminalService.activeInstance;
if (instance) {
instance.notifyFindWidgetFocusChanged(false);
}
this._findWidgetFocused.reset();
}
protected _onFindInputFocusTrackerFocus() {
this._findInputFocused.set(true);
}
protected _onFindInputFocusTrackerBlur() {
this._findInputFocused.reset();
}
findFirst() {
const instance = this._terminalService.activeInstance;
if (instance) {
if (instance.hasSelection()) {
instance.clearSelection();
}
instance.xterm?.findPrevious(this.inputValue, { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue() });
}
}
}
|