@codingame/monaco-vscode-search-service-override 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
  2. package/external/tslib/tslib.es6.js +11 -0
  3. package/override/vs/platform/dialogs/common/dialogs.js +10 -0
  4. package/package.json +2 -2
  5. package/search.js +4 -4
  6. package/vscode/src/vs/workbench/contrib/search/browser/anythingQuickAccess.js +796 -0
  7. package/vscode/src/vs/workbench/contrib/search/browser/media/anythingQuickAccess.css.js +6 -0
  8. package/vscode/src/vs/workbench/contrib/search/browser/media/searchview.css.js +6 -0
  9. package/vscode/src/vs/workbench/contrib/search/browser/patternInputWidget.js +234 -0
  10. package/vscode/src/vs/workbench/contrib/search/browser/quickTextSearch/textSearchQuickAccess.js +341 -0
  11. package/vscode/src/vs/workbench/contrib/search/browser/replaceContributions.js +9 -0
  12. package/vscode/src/vs/workbench/contrib/search/browser/replaceService.js +232 -0
  13. package/vscode/src/vs/workbench/contrib/search/browser/search.contribution.js +647 -0
  14. package/vscode/src/vs/workbench/contrib/search/browser/searchActionsCopy.js +209 -0
  15. package/vscode/src/vs/workbench/contrib/search/browser/searchActionsNav.js +511 -0
  16. package/vscode/src/vs/workbench/contrib/search/browser/searchActionsRemoveReplace.js +374 -0
  17. package/vscode/src/vs/workbench/contrib/search/browser/searchActionsSymbol.js +43 -0
  18. package/vscode/src/vs/workbench/contrib/search/browser/searchActionsTextQuickAccess.js +44 -0
  19. package/vscode/src/vs/workbench/contrib/search/browser/searchActionsTopBar.js +323 -0
  20. package/vscode/src/vs/workbench/contrib/search/browser/searchFindInput.js +103 -0
  21. package/vscode/src/vs/workbench/contrib/search/browser/searchIcons.js +106 -0
  22. package/vscode/src/vs/workbench/contrib/search/browser/searchMessage.js +66 -0
  23. package/vscode/src/vs/workbench/contrib/search/browser/searchResultsView.js +437 -0
  24. package/vscode/src/vs/workbench/contrib/search/browser/searchView.js +2177 -0
  25. package/vscode/src/vs/workbench/contrib/search/browser/searchWidget.js +674 -0
  26. package/vscode/src/vs/workbench/contrib/search/browser/symbolsQuickAccess.js +234 -0
  27. package/vscode/src/vs/workbench/contrib/search/common/cacheState.js +87 -0
  28. package/vscode/src/vs/workbench/contrib/searchEditor/browser/media/searchEditor.css.js +6 -0
  29. package/vscode/src/vs/workbench/contrib/searchEditor/browser/searchEditor.contribution.js +586 -0
  30. package/vscode/src/vs/workbench/contrib/searchEditor/browser/searchEditor.js +760 -0
  31. package/vscode/src/vs/workbench/contrib/searchEditor/browser/searchEditorActions.js +189 -0
  32. package/vscode/src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.js +320 -0
  33. package/vscode/src/vs/workbench/contrib/searchEditor/browser/searchEditorModel.js +138 -0
  34. package/vscode/src/vs/workbench/contrib/searchEditor/browser/searchEditorSerialization.js +293 -0
  35. package/vscode/src/vs/workbench/services/search/common/searchService.js +416 -0
@@ -0,0 +1,674 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { append, $, trackFocus } from 'vscode/vscode/vs/base/browser/dom';
3
+ import { ActionBar } from 'vscode/vscode/vs/base/browser/ui/actionbar/actionbar';
4
+ import { Button } from 'vscode/vscode/vs/base/browser/ui/button/button';
5
+ import { InputBox } from 'vscode/vscode/vs/base/browser/ui/inputbox/inputBox';
6
+ import { Widget } from 'vscode/vscode/vs/base/browser/ui/widget';
7
+ import { Action } from 'vscode/vscode/vs/base/common/actions';
8
+ import { Delayer } from 'vscode/vscode/vs/base/common/async';
9
+ import { Emitter } from 'vscode/vscode/vs/base/common/event';
10
+ import { CONTEXT_FIND_WIDGET_NOT_VISIBLE } from 'vscode/vscode/vs/editor/contrib/find/browser/findModel';
11
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
12
+ import { IClipboardService } from 'vscode/vscode/vs/platform/clipboard/common/clipboardService';
13
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
14
+ import { ContextKeyExpr, IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
15
+ import { IContextViewService, IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView';
16
+ import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
17
+ import { KeybindingsRegistry } from 'vscode/vscode/vs/platform/keybinding/common/keybindingsRegistry';
18
+ import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
19
+ import { ContextScopedReplaceInput } from 'vscode/vscode/vs/platform/history/browser/contextScopedHistoryWidget';
20
+ import { appendKeyBindingLabel, isSearchViewFocused, getSearchView } from 'vscode/vscode/vs/workbench/contrib/search/browser/searchActionsBase';
21
+ import { SearchContext } from 'vscode/vscode/vs/workbench/contrib/search/common/constants';
22
+ import { IAccessibilityService } from 'vscode/vscode/vs/platform/accessibility/common/accessibility';
23
+ import { isMacintosh } from 'vscode/vscode/vs/base/common/platform';
24
+ import { Toggle } from 'vscode/vscode/vs/base/browser/ui/toggle/toggle';
25
+ import { IViewsService } from 'vscode/vscode/vs/workbench/services/views/common/viewsService';
26
+ import { searchReplaceAllIcon, searchHideReplaceIcon, searchShowContextIcon, searchShowReplaceIcon } from './searchIcons.js';
27
+ import { ToggleSearchEditorContextLinesCommandId } from 'vscode/vscode/vs/workbench/contrib/searchEditor/browser/constants';
28
+ import { showHistoryKeybindingHint } from 'vscode/vscode/vs/platform/history/browser/historyWidgetKeybindingHint';
29
+ import { defaultToggleStyles, defaultInputBoxStyles } from 'vscode/vscode/vs/platform/theme/browser/defaultStyles';
30
+ import { NotebookFindFilters } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/find/findFilters';
31
+ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
32
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
33
+ import { NotebookEditorInput } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookEditorInput';
34
+ import { SearchFindInput } from './searchFindInput.js';
35
+ import { getDefaultHoverDelegate } from 'vscode/vscode/vs/base/browser/ui/hover/hoverDelegateFactory';
36
+ import { MutableDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
37
+
38
+ var SearchWidget_1;
39
+ const SingleLineInputHeight = 26;
40
+ class ReplaceAllAction extends Action {
41
+ static { this.ID = 'search.action.replaceAll'; }
42
+ constructor(_searchWidget) {
43
+ super(ReplaceAllAction.ID, '', ThemeIcon.asClassName(searchReplaceAllIcon), false);
44
+ this._searchWidget = _searchWidget;
45
+ }
46
+ set searchWidget(searchWidget) {
47
+ this._searchWidget = searchWidget;
48
+ }
49
+ run() {
50
+ if (this._searchWidget) {
51
+ return this._searchWidget.triggerReplaceAll();
52
+ }
53
+ return Promise.resolve(null);
54
+ }
55
+ }
56
+ const ctrlKeyMod = ((isMacintosh ? 256 : 2048) );
57
+ function stopPropagationForMultiLineUpwards(event, value, textarea) {
58
+ const isMultiline = !!value.match(/\n/);
59
+ if (textarea && (isMultiline || textarea.clientHeight > SingleLineInputHeight) && textarea.selectionStart > 0) {
60
+ event.stopPropagation();
61
+ return;
62
+ }
63
+ }
64
+ function stopPropagationForMultiLineDownwards(event, value, textarea) {
65
+ const isMultiline = !!value.match(/\n/);
66
+ if (textarea && (isMultiline || textarea.clientHeight > SingleLineInputHeight) && textarea.selectionEnd < textarea.value.length) {
67
+ event.stopPropagation();
68
+ return;
69
+ }
70
+ }
71
+ let SearchWidget = class SearchWidget extends Widget {
72
+ static { SearchWidget_1 = this; }
73
+ static { this.INPUT_MAX_HEIGHT = 134; }
74
+ static { this.REPLACE_ALL_DISABLED_LABEL = ( localizeWithPath(
75
+ 'vs/workbench/contrib/search/browser/searchWidget',
76
+ 'search.action.replaceAll.disabled.label',
77
+ "Replace All (Submit Search to Enable)"
78
+ )); }
79
+ static { this.REPLACE_ALL_ENABLED_LABEL = (keyBindingService2) => {
80
+ const kb = keyBindingService2.lookupKeybinding(ReplaceAllAction.ID);
81
+ return appendKeyBindingLabel(( localizeWithPath(
82
+ 'vs/workbench/contrib/search/browser/searchWidget',
83
+ 'search.action.replaceAll.enabled.label',
84
+ "Replace All"
85
+ )), kb);
86
+ }; }
87
+ constructor(container, options, contextViewService, contextKeyService, keybindingService, clipboardServce, configurationService, accessibilityService, contextMenuService, instantiationService, editorService) {
88
+ super();
89
+ this.contextViewService = contextViewService;
90
+ this.contextKeyService = contextKeyService;
91
+ this.keybindingService = keybindingService;
92
+ this.clipboardServce = clipboardServce;
93
+ this.configurationService = configurationService;
94
+ this.accessibilityService = accessibilityService;
95
+ this.contextMenuService = contextMenuService;
96
+ this.instantiationService = instantiationService;
97
+ this.editorService = editorService;
98
+ this.ignoreGlobalFindBufferOnNextFocus = false;
99
+ this.previousGlobalFindBufferValue = null;
100
+ this._onSearchSubmit = this._register(( new Emitter()));
101
+ this.onSearchSubmit = this._onSearchSubmit.event;
102
+ this._onSearchCancel = this._register(( new Emitter()));
103
+ this.onSearchCancel = this._onSearchCancel.event;
104
+ this._onReplaceToggled = this._register(( new Emitter()));
105
+ this.onReplaceToggled = this._onReplaceToggled.event;
106
+ this._onReplaceStateChange = this._register(( new Emitter()));
107
+ this.onReplaceStateChange = this._onReplaceStateChange.event;
108
+ this._onPreserveCaseChange = this._register(( new Emitter()));
109
+ this.onPreserveCaseChange = this._onPreserveCaseChange.event;
110
+ this._onReplaceValueChanged = this._register(( new Emitter()));
111
+ this.onReplaceValueChanged = this._onReplaceValueChanged.event;
112
+ this._onReplaceAll = this._register(( new Emitter()));
113
+ this.onReplaceAll = this._onReplaceAll.event;
114
+ this._onBlur = this._register(( new Emitter()));
115
+ this.onBlur = this._onBlur.event;
116
+ this._onDidHeightChange = this._register(( new Emitter()));
117
+ this.onDidHeightChange = this._onDidHeightChange.event;
118
+ this._onDidToggleContext = ( new Emitter());
119
+ this.onDidToggleContext = this._onDidToggleContext.event;
120
+ this.replaceActive = SearchContext.ReplaceActiveKey.bindTo(this.contextKeyService);
121
+ this.searchInputBoxFocused = SearchContext.SearchInputBoxFocusedKey.bindTo(this.contextKeyService);
122
+ this.replaceInputBoxFocused = SearchContext.ReplaceInputBoxFocusedKey.bindTo(this.contextKeyService);
123
+ const notebookOptions = options.notebookOptions ??
124
+ {
125
+ isInNotebookMarkdownInput: true,
126
+ isInNotebookMarkdownPreview: true,
127
+ isInNotebookCellInput: true,
128
+ isInNotebookCellOutput: true
129
+ };
130
+ this._notebookFilters = this._register(( new NotebookFindFilters(
131
+ notebookOptions.isInNotebookMarkdownInput,
132
+ notebookOptions.isInNotebookMarkdownPreview,
133
+ notebookOptions.isInNotebookCellInput,
134
+ notebookOptions.isInNotebookCellOutput
135
+ )));
136
+ this._register(this._notebookFilters.onDidChange(() => {
137
+ if (this.searchInput) {
138
+ this.searchInput.updateStyles();
139
+ }
140
+ }));
141
+ this._register(this.editorService.onDidEditorsChange((e) => {
142
+ if (this.searchInput &&
143
+ e.event.editor instanceof NotebookEditorInput &&
144
+ ((e.event.kind === 4 || e.event.kind === 5) )) {
145
+ this.searchInput.filterVisible = this._hasNotebookOpen();
146
+ }
147
+ }));
148
+ this._replaceHistoryDelayer = ( new Delayer(500));
149
+ this._toggleReplaceButtonListener = this._register(( new MutableDisposable()));
150
+ this.render(container, options);
151
+ this.configurationService.onDidChangeConfiguration(e => {
152
+ if (e.affectsConfiguration('editor.accessibilitySupport')) {
153
+ this.updateAccessibilitySupport();
154
+ }
155
+ });
156
+ this.accessibilityService.onDidChangeScreenReaderOptimized(() => this.updateAccessibilitySupport());
157
+ this.updateAccessibilitySupport();
158
+ }
159
+ _hasNotebookOpen() {
160
+ const editors = this.editorService.editors;
161
+ return ( editors.some(editor => editor instanceof NotebookEditorInput));
162
+ }
163
+ getNotebookFilters() {
164
+ return this._notebookFilters;
165
+ }
166
+ focus(select = true, focusReplace = false, suppressGlobalSearchBuffer = false) {
167
+ this.ignoreGlobalFindBufferOnNextFocus = suppressGlobalSearchBuffer;
168
+ if (focusReplace && this.isReplaceShown()) {
169
+ if (this.replaceInput) {
170
+ this.replaceInput.focus();
171
+ if (select) {
172
+ this.replaceInput.select();
173
+ }
174
+ }
175
+ }
176
+ else {
177
+ if (this.searchInput) {
178
+ this.searchInput.focus();
179
+ if (select) {
180
+ this.searchInput.select();
181
+ }
182
+ }
183
+ }
184
+ }
185
+ setWidth(width) {
186
+ this.searchInput?.inputBox.layout();
187
+ if (this.replaceInput) {
188
+ this.replaceInput.width = width - 28;
189
+ this.replaceInput.inputBox.layout();
190
+ }
191
+ }
192
+ clear() {
193
+ this.searchInput?.clear();
194
+ this.replaceInput?.setValue('');
195
+ this.setReplaceAllActionState(false);
196
+ }
197
+ isReplaceShown() {
198
+ return this.replaceContainer ? !this.replaceContainer.classList.contains('disabled') : false;
199
+ }
200
+ isReplaceActive() {
201
+ return !!this.replaceActive.get();
202
+ }
203
+ getReplaceValue() {
204
+ return this.replaceInput?.getValue() ?? '';
205
+ }
206
+ toggleReplace(show) {
207
+ if (show === undefined || show !== this.isReplaceShown()) {
208
+ this.onToggleReplaceButton();
209
+ }
210
+ }
211
+ getSearchHistory() {
212
+ return this.searchInput?.inputBox.getHistory() ?? [];
213
+ }
214
+ getReplaceHistory() {
215
+ return this.replaceInput?.inputBox.getHistory() ?? [];
216
+ }
217
+ prependSearchHistory(history) {
218
+ this.searchInput?.inputBox.prependHistory(history);
219
+ }
220
+ prependReplaceHistory(history) {
221
+ this.replaceInput?.inputBox.prependHistory(history);
222
+ }
223
+ clearHistory() {
224
+ this.searchInput?.inputBox.clearHistory();
225
+ this.replaceInput?.inputBox.clearHistory();
226
+ }
227
+ showNextSearchTerm() {
228
+ this.searchInput?.inputBox.showNextValue();
229
+ }
230
+ showPreviousSearchTerm() {
231
+ this.searchInput?.inputBox.showPreviousValue();
232
+ }
233
+ showNextReplaceTerm() {
234
+ this.replaceInput?.inputBox.showNextValue();
235
+ }
236
+ showPreviousReplaceTerm() {
237
+ this.replaceInput?.inputBox.showPreviousValue();
238
+ }
239
+ searchInputHasFocus() {
240
+ return !!this.searchInputBoxFocused.get();
241
+ }
242
+ replaceInputHasFocus() {
243
+ return !!this.replaceInput?.inputBox.hasFocus();
244
+ }
245
+ focusReplaceAllAction() {
246
+ this.replaceActionBar?.focus(true);
247
+ }
248
+ focusRegexAction() {
249
+ this.searchInput?.focusOnRegex();
250
+ }
251
+ render(container, options) {
252
+ this.domNode = append(container, $('.search-widget'));
253
+ this.domNode.style.position = 'relative';
254
+ if (!options._hideReplaceToggle) {
255
+ this.renderToggleReplaceButton(this.domNode);
256
+ }
257
+ this.renderSearchInput(this.domNode, options);
258
+ this.renderReplaceInput(this.domNode, options);
259
+ }
260
+ updateAccessibilitySupport() {
261
+ this.searchInput?.setFocusInputOnOptionClick(!this.accessibilityService.isScreenReaderOptimized());
262
+ }
263
+ renderToggleReplaceButton(parent) {
264
+ const opts = {
265
+ buttonBackground: undefined,
266
+ buttonBorder: undefined,
267
+ buttonForeground: undefined,
268
+ buttonHoverBackground: undefined,
269
+ buttonSecondaryBackground: undefined,
270
+ buttonSecondaryForeground: undefined,
271
+ buttonSecondaryHoverBackground: undefined,
272
+ buttonSeparator: undefined,
273
+ title: ( localizeWithPath(
274
+ 'vs/workbench/contrib/search/browser/searchWidget',
275
+ 'search.replace.toggle.button.title',
276
+ "Toggle Replace"
277
+ )),
278
+ hoverDelegate: getDefaultHoverDelegate('element'),
279
+ };
280
+ this.toggleReplaceButton = this._register(( new Button(parent, opts)));
281
+ this.toggleReplaceButton.element.setAttribute('aria-expanded', 'false');
282
+ this.toggleReplaceButton.element.classList.add('toggle-replace-button');
283
+ this.toggleReplaceButton.icon = searchHideReplaceIcon;
284
+ this._toggleReplaceButtonListener.value = this.toggleReplaceButton.onDidClick(() => this.onToggleReplaceButton());
285
+ }
286
+ renderSearchInput(parent, options) {
287
+ const inputOptions = {
288
+ label: ( localizeWithPath(
289
+ 'vs/workbench/contrib/search/browser/searchWidget',
290
+ 'label.Search',
291
+ 'Search: Type Search Term and press Enter to search'
292
+ )),
293
+ validation: (value) => this.validateSearchInput(value),
294
+ placeholder: ( localizeWithPath(
295
+ 'vs/workbench/contrib/search/browser/searchWidget',
296
+ 'search.placeHolder',
297
+ "Search"
298
+ )),
299
+ appendCaseSensitiveLabel: appendKeyBindingLabel('', this.keybindingService.lookupKeybinding("toggleSearchCaseSensitive" )),
300
+ appendWholeWordsLabel: appendKeyBindingLabel('', this.keybindingService.lookupKeybinding("toggleSearchWholeWord" )),
301
+ appendRegexLabel: appendKeyBindingLabel('', this.keybindingService.lookupKeybinding("toggleSearchRegex" )),
302
+ history: options.searchHistory,
303
+ showHistoryHint: () => showHistoryKeybindingHint(this.keybindingService),
304
+ flexibleHeight: true,
305
+ flexibleMaxHeight: SearchWidget_1.INPUT_MAX_HEIGHT,
306
+ showCommonFindToggles: true,
307
+ inputBoxStyles: options.inputBoxStyles,
308
+ toggleStyles: options.toggleStyles
309
+ };
310
+ const searchInputContainer = append(parent, $('.search-container.input-box'));
311
+ this.searchInput = this._register(( new SearchFindInput(
312
+ searchInputContainer,
313
+ this.contextViewService,
314
+ inputOptions,
315
+ this.contextKeyService,
316
+ this.contextMenuService,
317
+ this.instantiationService,
318
+ this._notebookFilters,
319
+ options.initialAIButtonVisibility ?? false,
320
+ this._hasNotebookOpen()
321
+ )));
322
+ this.searchInput.onKeyDown((keyboardEvent) => this.onSearchInputKeyDown(keyboardEvent));
323
+ this.searchInput.setValue(options.value || '');
324
+ this.searchInput.setRegex(!!options.isRegex);
325
+ this.searchInput.setCaseSensitive(!!options.isCaseSensitive);
326
+ this.searchInput.setWholeWords(!!options.isWholeWords);
327
+ this._register(this.searchInput.onCaseSensitiveKeyDown((keyboardEvent) => this.onCaseSensitiveKeyDown(keyboardEvent)));
328
+ this._register(this.searchInput.onRegexKeyDown((keyboardEvent) => this.onRegexKeyDown(keyboardEvent)));
329
+ this._register(this.searchInput.inputBox.onDidChange(() => this.onSearchInputChanged()));
330
+ this._register(this.searchInput.inputBox.onDidHeightChange(() => this._onDidHeightChange.fire()));
331
+ this._register(this.onReplaceValueChanged(() => {
332
+ this._replaceHistoryDelayer.trigger(() => this.replaceInput?.inputBox.addToHistory());
333
+ }));
334
+ this.searchInputFocusTracker = this._register(trackFocus(this.searchInput.inputBox.inputElement));
335
+ this._register(this.searchInputFocusTracker.onDidFocus(async () => {
336
+ this.searchInputBoxFocused.set(true);
337
+ const useGlobalFindBuffer = this.searchConfiguration.globalFindClipboard;
338
+ if (!this.ignoreGlobalFindBufferOnNextFocus && useGlobalFindBuffer) {
339
+ const globalBufferText = await this.clipboardServce.readFindText();
340
+ if (globalBufferText && this.previousGlobalFindBufferValue !== globalBufferText) {
341
+ this.searchInput?.inputBox.addToHistory();
342
+ this.searchInput?.setValue(globalBufferText);
343
+ this.searchInput?.select();
344
+ }
345
+ this.previousGlobalFindBufferValue = globalBufferText;
346
+ }
347
+ this.ignoreGlobalFindBufferOnNextFocus = false;
348
+ }));
349
+ this._register(this.searchInputFocusTracker.onDidBlur(() => this.searchInputBoxFocused.set(false)));
350
+ this.showContextToggle = ( new Toggle({
351
+ isChecked: false,
352
+ title: appendKeyBindingLabel(( localizeWithPath(
353
+ 'vs/workbench/contrib/search/browser/searchWidget',
354
+ 'showContext',
355
+ "Toggle Context Lines"
356
+ )), this.keybindingService.lookupKeybinding(ToggleSearchEditorContextLinesCommandId)),
357
+ icon: searchShowContextIcon,
358
+ hoverDelegate: getDefaultHoverDelegate('element'),
359
+ ...defaultToggleStyles
360
+ }));
361
+ this._register(this.showContextToggle.onChange(() => this.onContextLinesChanged()));
362
+ if (options.showContextToggle) {
363
+ this.contextLinesInput = ( new InputBox(
364
+ searchInputContainer,
365
+ this.contextViewService,
366
+ { type: 'number', inputBoxStyles: defaultInputBoxStyles }
367
+ ));
368
+ this.contextLinesInput.element.classList.add('context-lines-input');
369
+ this.contextLinesInput.value = '' + (this.configurationService.getValue('search').searchEditor.defaultNumberOfContextLines ?? 1);
370
+ this._register(this.contextLinesInput.onDidChange((value) => {
371
+ if (value !== '0') {
372
+ this.showContextToggle.checked = true;
373
+ }
374
+ this.onContextLinesChanged();
375
+ }));
376
+ append(searchInputContainer, this.showContextToggle.domNode);
377
+ }
378
+ }
379
+ onContextLinesChanged() {
380
+ this._onDidToggleContext.fire();
381
+ if (this.contextLinesInput.value.includes('-')) {
382
+ this.contextLinesInput.value = '0';
383
+ }
384
+ this._onDidToggleContext.fire();
385
+ }
386
+ setContextLines(lines) {
387
+ if (!this.contextLinesInput) {
388
+ return;
389
+ }
390
+ if (lines === 0) {
391
+ this.showContextToggle.checked = false;
392
+ }
393
+ else {
394
+ this.showContextToggle.checked = true;
395
+ this.contextLinesInput.value = '' + lines;
396
+ }
397
+ }
398
+ renderReplaceInput(parent, options) {
399
+ this.replaceContainer = append(parent, $('.replace-container.disabled'));
400
+ const replaceBox = append(this.replaceContainer, $('.replace-input'));
401
+ this.replaceInput = this._register(( new ContextScopedReplaceInput(replaceBox, this.contextViewService, {
402
+ label: ( localizeWithPath(
403
+ 'vs/workbench/contrib/search/browser/searchWidget',
404
+ 'label.Replace',
405
+ 'Replace: Type replace term and press Enter to preview'
406
+ )),
407
+ placeholder: ( localizeWithPath(
408
+ 'vs/workbench/contrib/search/browser/searchWidget',
409
+ 'search.replace.placeHolder',
410
+ "Replace"
411
+ )),
412
+ appendPreserveCaseLabel: appendKeyBindingLabel('', this.keybindingService.lookupKeybinding("toggleSearchPreserveCase" )),
413
+ history: options.replaceHistory,
414
+ showHistoryHint: () => showHistoryKeybindingHint(this.keybindingService),
415
+ flexibleHeight: true,
416
+ flexibleMaxHeight: SearchWidget_1.INPUT_MAX_HEIGHT,
417
+ inputBoxStyles: options.inputBoxStyles,
418
+ toggleStyles: options.toggleStyles
419
+ }, this.contextKeyService, true)));
420
+ this._register(this.replaceInput.onDidOptionChange(viaKeyboard => {
421
+ if (!viaKeyboard) {
422
+ if (this.replaceInput) {
423
+ this._onPreserveCaseChange.fire(this.replaceInput.getPreserveCase());
424
+ }
425
+ }
426
+ }));
427
+ this.replaceInput.onKeyDown((keyboardEvent) => this.onReplaceInputKeyDown(keyboardEvent));
428
+ this.replaceInput.setValue(options.replaceValue || '');
429
+ this._register(this.replaceInput.inputBox.onDidChange(() => this._onReplaceValueChanged.fire()));
430
+ this._register(this.replaceInput.inputBox.onDidHeightChange(() => this._onDidHeightChange.fire()));
431
+ this.replaceAllAction = ( new ReplaceAllAction(this));
432
+ this.replaceAllAction.label = SearchWidget_1.REPLACE_ALL_DISABLED_LABEL;
433
+ this.replaceActionBar = this._register(( new ActionBar(this.replaceContainer)));
434
+ this.replaceActionBar.push([this.replaceAllAction], { icon: true, label: false });
435
+ this.onkeydown(this.replaceActionBar.domNode, (keyboardEvent) => this.onReplaceActionbarKeyDown(keyboardEvent));
436
+ this.replaceInputFocusTracker = this._register(trackFocus(this.replaceInput.inputBox.inputElement));
437
+ this._register(this.replaceInputFocusTracker.onDidFocus(() => this.replaceInputBoxFocused.set(true)));
438
+ this._register(this.replaceInputFocusTracker.onDidBlur(() => this.replaceInputBoxFocused.set(false)));
439
+ this._register(this.replaceInput.onPreserveCaseKeyDown((keyboardEvent) => this.onPreserveCaseKeyDown(keyboardEvent)));
440
+ }
441
+ triggerReplaceAll() {
442
+ this._onReplaceAll.fire();
443
+ return Promise.resolve(null);
444
+ }
445
+ onToggleReplaceButton() {
446
+ this.replaceContainer?.classList.toggle('disabled');
447
+ if (this.isReplaceShown()) {
448
+ this.toggleReplaceButton?.element.classList.remove(...ThemeIcon.asClassNameArray(searchHideReplaceIcon));
449
+ this.toggleReplaceButton?.element.classList.add(...ThemeIcon.asClassNameArray(searchShowReplaceIcon));
450
+ }
451
+ else {
452
+ this.toggleReplaceButton?.element.classList.remove(...ThemeIcon.asClassNameArray(searchShowReplaceIcon));
453
+ this.toggleReplaceButton?.element.classList.add(...ThemeIcon.asClassNameArray(searchHideReplaceIcon));
454
+ }
455
+ this.toggleReplaceButton?.element.setAttribute('aria-expanded', this.isReplaceShown() ? 'true' : 'false');
456
+ this.updateReplaceActiveState();
457
+ this._onReplaceToggled.fire();
458
+ }
459
+ setValue(value) {
460
+ this.searchInput?.setValue(value);
461
+ }
462
+ setReplaceAllActionState(enabled) {
463
+ if (this.replaceAllAction && (this.replaceAllAction.enabled !== enabled)) {
464
+ this.replaceAllAction.enabled = enabled;
465
+ this.replaceAllAction.label = enabled ? SearchWidget_1.REPLACE_ALL_ENABLED_LABEL(this.keybindingService) : SearchWidget_1.REPLACE_ALL_DISABLED_LABEL;
466
+ this.updateReplaceActiveState();
467
+ }
468
+ }
469
+ updateReplaceActiveState() {
470
+ const currentState = this.isReplaceActive();
471
+ const newState = this.isReplaceShown() && !!this.replaceAllAction?.enabled;
472
+ if (currentState !== newState) {
473
+ this.replaceActive.set(newState);
474
+ this._onReplaceStateChange.fire(newState);
475
+ this.replaceInput?.inputBox.layout();
476
+ }
477
+ }
478
+ validateSearchInput(value) {
479
+ if (value.length === 0) {
480
+ return null;
481
+ }
482
+ if (!(this.searchInput?.getRegex())) {
483
+ return null;
484
+ }
485
+ return null;
486
+ }
487
+ onSearchInputChanged() {
488
+ this.searchInput?.clearMessage();
489
+ this.setReplaceAllActionState(false);
490
+ if (this.searchConfiguration.searchOnType) {
491
+ const delayMultiplierFromAISearch = (this.searchInput && this.searchInput.isAIEnabled) ? 5 : 1;
492
+ if (this.searchInput?.getRegex()) {
493
+ try {
494
+ const regex = ( new RegExp(this.searchInput.getValue(), 'ug'));
495
+ const matchienessHeuristic = `
496
+ ~!@#$%^&*()_+
497
+ \`1234567890-=
498
+ qwertyuiop[]\\
499
+ QWERTYUIOP{}|
500
+ asdfghjkl;'
501
+ ASDFGHJKL:"
502
+ zxcvbnm,./
503
+ ZXCVBNM<>? `.match(regex)?.length ?? 0;
504
+ const delayMultiplier = matchienessHeuristic < 50 ? 1 :
505
+ matchienessHeuristic < 100 ? 5 :
506
+ 10;
507
+ this.submitSearch(true, this.searchConfiguration.searchOnTypeDebouncePeriod * delayMultiplier * delayMultiplierFromAISearch);
508
+ }
509
+ catch {
510
+ }
511
+ }
512
+ else {
513
+ this.submitSearch(true, this.searchConfiguration.searchOnTypeDebouncePeriod * delayMultiplierFromAISearch);
514
+ }
515
+ }
516
+ }
517
+ onSearchInputKeyDown(keyboardEvent) {
518
+ if (keyboardEvent.equals(ctrlKeyMod | 3 )) {
519
+ this.searchInput?.inputBox.insertAtCursor('\n');
520
+ keyboardEvent.preventDefault();
521
+ }
522
+ if (keyboardEvent.equals(3 )) {
523
+ this.searchInput?.onSearchSubmit();
524
+ this.submitSearch();
525
+ keyboardEvent.preventDefault();
526
+ }
527
+ else if (keyboardEvent.equals(9 )) {
528
+ this._onSearchCancel.fire({ focus: true });
529
+ keyboardEvent.preventDefault();
530
+ }
531
+ else if (keyboardEvent.equals(2 )) {
532
+ if (this.isReplaceShown()) {
533
+ this.replaceInput?.focus();
534
+ }
535
+ else {
536
+ this.searchInput?.focusOnCaseSensitive();
537
+ }
538
+ keyboardEvent.preventDefault();
539
+ }
540
+ else if (keyboardEvent.equals(16 )) {
541
+ stopPropagationForMultiLineUpwards(keyboardEvent, this.searchInput?.getValue() ?? '', this.searchInput?.domNode.querySelector('textarea') ?? null);
542
+ }
543
+ else if (keyboardEvent.equals(18 )) {
544
+ stopPropagationForMultiLineDownwards(keyboardEvent, this.searchInput?.getValue() ?? '', this.searchInput?.domNode.querySelector('textarea') ?? null);
545
+ }
546
+ }
547
+ onCaseSensitiveKeyDown(keyboardEvent) {
548
+ if (keyboardEvent.equals(1024 | 2 )) {
549
+ if (this.isReplaceShown()) {
550
+ this.replaceInput?.focus();
551
+ keyboardEvent.preventDefault();
552
+ }
553
+ }
554
+ }
555
+ onRegexKeyDown(keyboardEvent) {
556
+ if (keyboardEvent.equals(2 )) {
557
+ if (this.isReplaceShown()) {
558
+ this.replaceInput?.focusOnPreserve();
559
+ keyboardEvent.preventDefault();
560
+ }
561
+ }
562
+ }
563
+ onPreserveCaseKeyDown(keyboardEvent) {
564
+ if (keyboardEvent.equals(2 )) {
565
+ if (this.isReplaceActive()) {
566
+ this.focusReplaceAllAction();
567
+ }
568
+ else {
569
+ this._onBlur.fire();
570
+ }
571
+ keyboardEvent.preventDefault();
572
+ }
573
+ else if (keyboardEvent.equals(1024 | 2 )) {
574
+ this.focusRegexAction();
575
+ keyboardEvent.preventDefault();
576
+ }
577
+ }
578
+ onReplaceInputKeyDown(keyboardEvent) {
579
+ if (keyboardEvent.equals(ctrlKeyMod | 3 )) {
580
+ this.replaceInput?.inputBox.insertAtCursor('\n');
581
+ keyboardEvent.preventDefault();
582
+ }
583
+ if (keyboardEvent.equals(3 )) {
584
+ this.submitSearch();
585
+ keyboardEvent.preventDefault();
586
+ }
587
+ else if (keyboardEvent.equals(2 )) {
588
+ this.searchInput?.focusOnCaseSensitive();
589
+ keyboardEvent.preventDefault();
590
+ }
591
+ else if (keyboardEvent.equals(1024 | 2 )) {
592
+ this.searchInput?.focus();
593
+ keyboardEvent.preventDefault();
594
+ }
595
+ else if (keyboardEvent.equals(16 )) {
596
+ stopPropagationForMultiLineUpwards(keyboardEvent, this.replaceInput?.getValue() ?? '', this.replaceInput?.domNode.querySelector('textarea') ?? null);
597
+ }
598
+ else if (keyboardEvent.equals(18 )) {
599
+ stopPropagationForMultiLineDownwards(keyboardEvent, this.replaceInput?.getValue() ?? '', this.replaceInput?.domNode.querySelector('textarea') ?? null);
600
+ }
601
+ }
602
+ onReplaceActionbarKeyDown(keyboardEvent) {
603
+ if (keyboardEvent.equals(1024 | 2 )) {
604
+ this.focusRegexAction();
605
+ keyboardEvent.preventDefault();
606
+ }
607
+ }
608
+ async submitSearch(triggeredOnType = false, delay = 0) {
609
+ this.searchInput?.validate();
610
+ if (!this.searchInput?.inputBox.isInputValid()) {
611
+ return;
612
+ }
613
+ const value = this.searchInput.getValue();
614
+ const useGlobalFindBuffer = this.searchConfiguration.globalFindClipboard;
615
+ if (value && useGlobalFindBuffer) {
616
+ await this.clipboardServce.writeFindText(value);
617
+ }
618
+ this._onSearchSubmit.fire({ triggeredOnType, delay });
619
+ }
620
+ getContextLines() {
621
+ return this.showContextToggle.checked ? +this.contextLinesInput.value : 0;
622
+ }
623
+ modifyContextLines(increase) {
624
+ const current = +this.contextLinesInput.value;
625
+ const modified = current + (increase ? 1 : -1);
626
+ this.showContextToggle.checked = modified !== 0;
627
+ this.contextLinesInput.value = '' + modified;
628
+ }
629
+ toggleContextLines() {
630
+ this.showContextToggle.checked = !this.showContextToggle.checked;
631
+ this.onContextLinesChanged();
632
+ }
633
+ dispose() {
634
+ this.setReplaceAllActionState(false);
635
+ super.dispose();
636
+ }
637
+ get searchConfiguration() {
638
+ return this.configurationService.getValue('search');
639
+ }
640
+ };
641
+ SearchWidget = SearchWidget_1 = ( __decorate([
642
+ ( __param(2, IContextViewService)),
643
+ ( __param(3, IContextKeyService)),
644
+ ( __param(4, IKeybindingService)),
645
+ ( __param(5, IClipboardService)),
646
+ ( __param(6, IConfigurationService)),
647
+ ( __param(7, IAccessibilityService)),
648
+ ( __param(8, IContextMenuService)),
649
+ ( __param(9, IInstantiationService)),
650
+ ( __param(10, IEditorService))
651
+ ], SearchWidget));
652
+ function registerContributions() {
653
+ KeybindingsRegistry.registerCommandAndKeybindingRule({
654
+ id: ReplaceAllAction.ID,
655
+ weight: 200 ,
656
+ when: ( ContextKeyExpr.and(
657
+ SearchContext.SearchViewVisibleKey,
658
+ SearchContext.ReplaceActiveKey,
659
+ CONTEXT_FIND_WIDGET_NOT_VISIBLE
660
+ )),
661
+ primary: 512 | 2048 | 3 ,
662
+ handler: accessor => {
663
+ const viewsService = accessor.get(IViewsService);
664
+ if (isSearchViewFocused(viewsService)) {
665
+ const searchView = getSearchView(viewsService);
666
+ if (searchView) {
667
+ ( new ReplaceAllAction(searchView.searchAndReplaceWidget)).run();
668
+ }
669
+ }
670
+ }
671
+ });
672
+ }
673
+
674
+ export { SearchWidget, registerContributions };