@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,760 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { $, append, addDisposableListener, EventType, EventHelper, clearNode, getTotalHeight } from 'vscode/vscode/vs/base/browser/dom';
3
+ import { StandardKeyboardEvent } from 'vscode/vscode/vs/base/browser/keyboardEvent';
4
+ import { alert } from 'vscode/vscode/vs/base/browser/ui/aria/aria';
5
+ import { Delayer } from 'vscode/vscode/vs/base/common/async';
6
+ import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
7
+ import { assertIsDefined } from 'vscode/vscode/vs/base/common/types';
8
+ import './media/searchEditor.css.js';
9
+ import { Position } from 'vscode/vscode/vs/editor/common/core/position';
10
+ import { Range } from 'vscode/vscode/vs/editor/common/core/range';
11
+ import { Selection } from 'vscode/vscode/vs/editor/common/core/selection';
12
+ import { IModelService } from 'vscode/vscode/vs/editor/common/services/model';
13
+ import { ITextResourceConfigurationService } from 'vscode/vscode/vs/editor/common/services/textResourceConfiguration';
14
+ import { ReferencesController } from 'vscode/vscode/vs/editor/contrib/gotoSymbol/browser/peek/referencesController';
15
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
16
+ import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
17
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
18
+ import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
19
+ import { IContextViewService } from 'vscode/vscode/vs/platform/contextview/browser/contextView';
20
+ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
21
+ import { ServiceCollection } from 'vscode/vscode/vs/platform/instantiation/common/serviceCollection';
22
+ import { ILabelService } from 'vscode/vscode/vs/platform/label/common/label';
23
+ import { LongRunningOperation, IEditorProgressService } from 'vscode/vscode/vs/platform/progress/common/progress';
24
+ import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
25
+ import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
26
+ import { registerColor } from 'vscode/vscode/vs/platform/theme/common/colorUtils';
27
+ import 'vscode/vscode/vs/platform/theme/common/colors/baseColors';
28
+ import 'vscode/vscode/vs/platform/theme/common/colors/chartsColors';
29
+ import 'vscode/vscode/vs/platform/theme/common/colors/editorColors';
30
+ import { inputBorder } from 'vscode/vscode/vs/platform/theme/common/colors/inputColors';
31
+ import 'vscode/vscode/vs/platform/theme/common/colors/listColors';
32
+ import 'vscode/vscode/vs/platform/theme/common/colors/menuColors';
33
+ import 'vscode/vscode/vs/platform/theme/common/colors/minimapColors';
34
+ import 'vscode/vscode/vs/platform/theme/common/colors/miscColors';
35
+ import 'vscode/vscode/vs/platform/theme/common/colors/quickpickColors';
36
+ import 'vscode/vscode/vs/platform/theme/common/colors/searchColors';
37
+ import { IThemeService } from 'vscode/vscode/vs/platform/theme/common/themeService';
38
+ import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
39
+ import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace';
40
+ import { AbstractTextCodeEditor } from 'vscode/vscode/vs/workbench/browser/parts/editor/textCodeEditor';
41
+ import { IncludePatternInputWidget, ExcludePatternInputWidget } from '../../search/browser/patternInputWidget.js';
42
+ import { SearchWidget } from '../../search/browser/searchWidget.js';
43
+ import { QueryBuilder } from 'vscode/vscode/vs/workbench/services/search/common/queryBuilder';
44
+ import { getOutOfWorkspaceEditorResources } from 'vscode/vscode/vs/workbench/contrib/search/common/search';
45
+ import { SearchModel } from 'vscode/vscode/vs/workbench/contrib/search/browser/searchModel';
46
+ import { SearchEditorID, InSearchEditor, SearchEditorInputTypeId } from 'vscode/vscode/vs/workbench/contrib/searchEditor/browser/constants';
47
+ import { serializeSearchResultForEditor } from './searchEditorSerialization.js';
48
+ import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService';
49
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
50
+ import { searchDetailsIcon } from '../../search/browser/searchIcons.js';
51
+ import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
52
+ import { IOpenerService } from 'vscode/vscode/vs/platform/opener/common/opener';
53
+ import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
54
+ import { renderSearchMessage } from '../../search/browser/searchMessage.js';
55
+ import { EditorExtensionsRegistry } from 'vscode/vscode/vs/editor/browser/editorExtensions';
56
+ import { UnusualLineTerminatorsDetector } from 'vscode/vscode/vs/editor/contrib/unusualLineTerminators/browser/unusualLineTerminators';
57
+ import { getInputBoxStyle, defaultToggleStyles } from 'vscode/vscode/vs/platform/theme/browser/defaultStyles';
58
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
59
+ import { SearchContext } from 'vscode/vscode/vs/workbench/contrib/search/common/constants';
60
+ import { setupCustomHover } from 'vscode/vscode/vs/base/browser/ui/hover/updatableHoverWidget';
61
+ import { getDefaultHoverDelegate } from 'vscode/vscode/vs/base/browser/ui/hover/hoverDelegateFactory';
62
+
63
+ var SearchEditor_1;
64
+ const RESULT_LINE_REGEX = /^(\s+)(\d+)(: | )(\s*)(.*)$/;
65
+ const FILE_LINE_REGEX = /^(\S.*):$/;
66
+ let SearchEditor = class SearchEditor extends AbstractTextCodeEditor {
67
+ static { SearchEditor_1 = this; }
68
+ static { this.ID = SearchEditorID; }
69
+ static { this.SEARCH_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'searchEditorViewState'; }
70
+ get searchResultEditor() { return this.editorControl; }
71
+ constructor(group, telemetryService, themeService, storageService, modelService, contextService, labelService, instantiationService, contextViewService, commandService, openerService, notificationService, progressService, textResourceService, editorGroupService, editorService, configurationService, fileService, logService) {
72
+ super(SearchEditor_1.ID, group, telemetryService, instantiationService, storageService, textResourceService, themeService, editorService, editorGroupService, fileService);
73
+ this.modelService = modelService;
74
+ this.contextService = contextService;
75
+ this.labelService = labelService;
76
+ this.contextViewService = contextViewService;
77
+ this.commandService = commandService;
78
+ this.openerService = openerService;
79
+ this.notificationService = notificationService;
80
+ this.configurationService = configurationService;
81
+ this.logService = logService;
82
+ this.runSearchDelayer = ( new Delayer(0));
83
+ this.pauseSearching = false;
84
+ this.showingIncludesExcludes = false;
85
+ this.ongoingOperations = 0;
86
+ this.updatingModelForSearch = false;
87
+ this.container = $('.search-editor');
88
+ this.searchOperation = this._register(( new LongRunningOperation(progressService)));
89
+ this._register(this.messageDisposables = ( new DisposableStore()));
90
+ this.searchHistoryDelayer = ( new Delayer(2000));
91
+ this.searchModel = this._register(this.instantiationService.createInstance(SearchModel));
92
+ }
93
+ createEditor(parent) {
94
+ append(parent, this.container);
95
+ this.queryEditorContainer = append(this.container, $('.query-container'));
96
+ const searchResultContainer = append(this.container, $('.search-results'));
97
+ super.createEditor(searchResultContainer);
98
+ this.registerEditorListeners();
99
+ const scopedContextKeyService = assertIsDefined(this.scopedContextKeyService);
100
+ InSearchEditor.bindTo(scopedContextKeyService).set(true);
101
+ this.createQueryEditor(this.queryEditorContainer, this.instantiationService.createChild(( new ServiceCollection([IContextKeyService, scopedContextKeyService]))), SearchContext.InputBoxFocusedKey.bindTo(scopedContextKeyService));
102
+ }
103
+ createQueryEditor(container, scopedInstantiationService, inputBoxFocusedContextKey) {
104
+ const searchEditorInputboxStyles = getInputBoxStyle({ inputBorder: searchEditorTextInputBorder });
105
+ this.queryEditorWidget = this._register(scopedInstantiationService.createInstance(SearchWidget, container, { _hideReplaceToggle: true, showContextToggle: true, inputBoxStyles: searchEditorInputboxStyles, toggleStyles: defaultToggleStyles }));
106
+ this._register(this.queryEditorWidget.onReplaceToggled(() => this.reLayout()));
107
+ this._register(this.queryEditorWidget.onDidHeightChange(() => this.reLayout()));
108
+ this._register(this.queryEditorWidget.onSearchSubmit(({ delay }) => this.triggerSearch({ delay })));
109
+ if (this.queryEditorWidget.searchInput) {
110
+ this._register(this.queryEditorWidget.searchInput.onDidOptionChange(() => this.triggerSearch({ resetCursor: false })));
111
+ }
112
+ else {
113
+ this.logService.warn('SearchEditor: SearchWidget.searchInput is undefined, cannot register onDidOptionChange listener');
114
+ }
115
+ this._register(this.queryEditorWidget.onDidToggleContext(() => this.triggerSearch({ resetCursor: false })));
116
+ this.includesExcludesContainer = append(container, $('.includes-excludes'));
117
+ this.toggleQueryDetailsButton = append(this.includesExcludesContainer, $('.expand' + ThemeIcon.asCSSSelector(searchDetailsIcon), { tabindex: 0, role: 'button' }));
118
+ this._register(setupCustomHover(getDefaultHoverDelegate('element'), this.toggleQueryDetailsButton, ( localizeWithPath(
119
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
120
+ 'moreSearch',
121
+ "Toggle Search Details"
122
+ ))));
123
+ this._register(addDisposableListener(this.toggleQueryDetailsButton, EventType.CLICK, e => {
124
+ EventHelper.stop(e);
125
+ this.toggleIncludesExcludes();
126
+ }));
127
+ this._register(addDisposableListener(this.toggleQueryDetailsButton, EventType.KEY_UP, (e) => {
128
+ const event = ( new StandardKeyboardEvent(e));
129
+ if (event.equals(3 ) || event.equals(10 )) {
130
+ EventHelper.stop(e);
131
+ this.toggleIncludesExcludes();
132
+ }
133
+ }));
134
+ this._register(addDisposableListener(this.toggleQueryDetailsButton, EventType.KEY_DOWN, (e) => {
135
+ const event = ( new StandardKeyboardEvent(e));
136
+ if (event.equals(1024 | 2 )) {
137
+ if (this.queryEditorWidget.isReplaceActive()) {
138
+ this.queryEditorWidget.focusReplaceAllAction();
139
+ }
140
+ else {
141
+ this.queryEditorWidget.isReplaceShown() ? this.queryEditorWidget.replaceInput?.focusOnPreserve() : this.queryEditorWidget.focusRegexAction();
142
+ }
143
+ EventHelper.stop(e);
144
+ }
145
+ }));
146
+ const folderIncludesList = append(this.includesExcludesContainer, $('.file-types.includes'));
147
+ const filesToIncludeTitle = ( localizeWithPath(
148
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
149
+ 'searchScope.includes',
150
+ "files to include"
151
+ ));
152
+ append(folderIncludesList, $('h4', undefined, filesToIncludeTitle));
153
+ this.inputPatternIncludes = this._register(scopedInstantiationService.createInstance(IncludePatternInputWidget, folderIncludesList, this.contextViewService, {
154
+ ariaLabel: ( localizeWithPath(
155
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
156
+ 'label.includes',
157
+ 'Search Include Patterns'
158
+ )),
159
+ inputBoxStyles: searchEditorInputboxStyles
160
+ }));
161
+ this.inputPatternIncludes.onSubmit(triggeredOnType => this.triggerSearch({ resetCursor: false, delay: triggeredOnType ? this.searchConfig.searchOnTypeDebouncePeriod : 0 }));
162
+ this._register(this.inputPatternIncludes.onChangeSearchInEditorsBox(() => this.triggerSearch()));
163
+ const excludesList = append(this.includesExcludesContainer, $('.file-types.excludes'));
164
+ const excludesTitle = ( localizeWithPath(
165
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
166
+ 'searchScope.excludes',
167
+ "files to exclude"
168
+ ));
169
+ append(excludesList, $('h4', undefined, excludesTitle));
170
+ this.inputPatternExcludes = this._register(scopedInstantiationService.createInstance(ExcludePatternInputWidget, excludesList, this.contextViewService, {
171
+ ariaLabel: ( localizeWithPath(
172
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
173
+ 'label.excludes',
174
+ 'Search Exclude Patterns'
175
+ )),
176
+ inputBoxStyles: searchEditorInputboxStyles
177
+ }));
178
+ this.inputPatternExcludes.onSubmit(triggeredOnType => this.triggerSearch({ resetCursor: false, delay: triggeredOnType ? this.searchConfig.searchOnTypeDebouncePeriod : 0 }));
179
+ this._register(this.inputPatternExcludes.onChangeIgnoreBox(() => this.triggerSearch()));
180
+ this.messageBox = append(container, $('.messages.text-search-provider-messages'));
181
+ [this.queryEditorWidget.searchInputFocusTracker, this.queryEditorWidget.replaceInputFocusTracker, this.inputPatternExcludes.inputFocusTracker, this.inputPatternIncludes.inputFocusTracker]
182
+ .forEach(tracker => {
183
+ if (!tracker) {
184
+ return;
185
+ }
186
+ this._register(tracker.onDidFocus(() => setTimeout(() => inputBoxFocusedContextKey.set(true), 0)));
187
+ this._register(tracker.onDidBlur(() => inputBoxFocusedContextKey.set(false)));
188
+ });
189
+ }
190
+ toggleRunAgainMessage(show) {
191
+ clearNode(this.messageBox);
192
+ this.messageDisposables.clear();
193
+ if (show) {
194
+ const runAgainLink = append(this.messageBox, $('a.pointer.prominent.message', {}, ( localizeWithPath(
195
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
196
+ 'runSearch',
197
+ "Run Search"
198
+ ))));
199
+ this.messageDisposables.add(addDisposableListener(runAgainLink, EventType.CLICK, async () => {
200
+ await this.triggerSearch();
201
+ this.searchResultEditor.focus();
202
+ }));
203
+ }
204
+ }
205
+ _getContributions() {
206
+ const skipContributions = [UnusualLineTerminatorsDetector.ID];
207
+ return EditorExtensionsRegistry.getEditorContributions().filter(c => skipContributions.indexOf(c.id) === -1);
208
+ }
209
+ getCodeEditorWidgetOptions() {
210
+ return { contributions: this._getContributions() };
211
+ }
212
+ registerEditorListeners() {
213
+ this.searchResultEditor.onMouseUp(e => {
214
+ if (e.event.detail === 1) {
215
+ const behaviour = this.searchConfig.searchEditor.singleClickBehaviour;
216
+ const position = e.target.position;
217
+ if (position && behaviour === 'peekDefinition') {
218
+ const line = this.searchResultEditor.getModel()?.getLineContent(position.lineNumber) ?? '';
219
+ if (line.match(FILE_LINE_REGEX) || line.match(RESULT_LINE_REGEX)) {
220
+ this.searchResultEditor.setSelection(Range.fromPositions(position));
221
+ this.commandService.executeCommand('editor.action.peekDefinition');
222
+ }
223
+ }
224
+ }
225
+ else if (e.event.detail === 2) {
226
+ const behaviour = this.searchConfig.searchEditor.doubleClickBehaviour;
227
+ const position = e.target.position;
228
+ if (position && behaviour !== 'selectWord') {
229
+ const line = this.searchResultEditor.getModel()?.getLineContent(position.lineNumber) ?? '';
230
+ if (line.match(RESULT_LINE_REGEX)) {
231
+ this.searchResultEditor.setSelection(Range.fromPositions(position));
232
+ this.commandService.executeCommand(behaviour === 'goToLocation' ? 'editor.action.goToDeclaration' : 'editor.action.openDeclarationToTheSide');
233
+ }
234
+ else if (line.match(FILE_LINE_REGEX)) {
235
+ this.searchResultEditor.setSelection(Range.fromPositions(position));
236
+ this.commandService.executeCommand('editor.action.peekDefinition');
237
+ }
238
+ }
239
+ }
240
+ });
241
+ this._register(this.searchResultEditor.onDidChangeModelContent(() => {
242
+ if (!this.updatingModelForSearch) {
243
+ this.getInput()?.setDirty(true);
244
+ }
245
+ }));
246
+ }
247
+ getControl() {
248
+ return this.searchResultEditor;
249
+ }
250
+ focus() {
251
+ super.focus();
252
+ const viewState = this.loadEditorViewState(this.getInput());
253
+ if (viewState && viewState.focused === 'editor') {
254
+ this.searchResultEditor.focus();
255
+ }
256
+ else {
257
+ this.queryEditorWidget.focus();
258
+ }
259
+ }
260
+ focusSearchInput() {
261
+ this.queryEditorWidget.searchInput?.focus();
262
+ }
263
+ focusFilesToIncludeInput() {
264
+ if (!this.showingIncludesExcludes) {
265
+ this.toggleIncludesExcludes(true);
266
+ }
267
+ this.inputPatternIncludes.focus();
268
+ }
269
+ focusFilesToExcludeInput() {
270
+ if (!this.showingIncludesExcludes) {
271
+ this.toggleIncludesExcludes(true);
272
+ }
273
+ this.inputPatternExcludes.focus();
274
+ }
275
+ focusNextInput() {
276
+ if (this.queryEditorWidget.searchInputHasFocus()) {
277
+ if (this.showingIncludesExcludes) {
278
+ this.inputPatternIncludes.focus();
279
+ }
280
+ else {
281
+ this.searchResultEditor.focus();
282
+ }
283
+ }
284
+ else if (this.inputPatternIncludes.inputHasFocus()) {
285
+ this.inputPatternExcludes.focus();
286
+ }
287
+ else if (this.inputPatternExcludes.inputHasFocus()) {
288
+ this.searchResultEditor.focus();
289
+ }
290
+ else if (this.searchResultEditor.hasWidgetFocus()) ;
291
+ }
292
+ focusPrevInput() {
293
+ if (this.queryEditorWidget.searchInputHasFocus()) {
294
+ this.searchResultEditor.focus();
295
+ }
296
+ else if (this.inputPatternIncludes.inputHasFocus()) {
297
+ this.queryEditorWidget.searchInput?.focus();
298
+ }
299
+ else if (this.inputPatternExcludes.inputHasFocus()) {
300
+ this.inputPatternIncludes.focus();
301
+ }
302
+ else if (this.searchResultEditor.hasWidgetFocus()) ;
303
+ }
304
+ setQuery(query) {
305
+ this.queryEditorWidget.searchInput?.setValue(query);
306
+ }
307
+ selectQuery() {
308
+ this.queryEditorWidget.searchInput?.select();
309
+ }
310
+ toggleWholeWords() {
311
+ this.queryEditorWidget.searchInput?.setWholeWords(!this.queryEditorWidget.searchInput.getWholeWords());
312
+ this.triggerSearch({ resetCursor: false });
313
+ }
314
+ toggleRegex() {
315
+ this.queryEditorWidget.searchInput?.setRegex(!this.queryEditorWidget.searchInput.getRegex());
316
+ this.triggerSearch({ resetCursor: false });
317
+ }
318
+ toggleCaseSensitive() {
319
+ this.queryEditorWidget.searchInput?.setCaseSensitive(!this.queryEditorWidget.searchInput.getCaseSensitive());
320
+ this.triggerSearch({ resetCursor: false });
321
+ }
322
+ toggleContextLines() {
323
+ this.queryEditorWidget.toggleContextLines();
324
+ }
325
+ modifyContextLines(increase) {
326
+ this.queryEditorWidget.modifyContextLines(increase);
327
+ }
328
+ toggleQueryDetails(shouldShow) {
329
+ this.toggleIncludesExcludes(shouldShow);
330
+ }
331
+ deleteResultBlock() {
332
+ const linesToDelete = ( new Set());
333
+ const selections = this.searchResultEditor.getSelections();
334
+ const model = this.searchResultEditor.getModel();
335
+ if (!(selections && model)) {
336
+ return;
337
+ }
338
+ const maxLine = model.getLineCount();
339
+ const minLine = 1;
340
+ const deleteUp = (start) => {
341
+ for (let cursor = start; cursor >= minLine; cursor--) {
342
+ const line = model.getLineContent(cursor);
343
+ linesToDelete.add(cursor);
344
+ if (line[0] !== undefined && line[0] !== ' ') {
345
+ break;
346
+ }
347
+ }
348
+ };
349
+ const deleteDown = (start) => {
350
+ linesToDelete.add(start);
351
+ for (let cursor = start + 1; cursor <= maxLine; cursor++) {
352
+ const line = model.getLineContent(cursor);
353
+ if (line[0] !== undefined && line[0] !== ' ') {
354
+ return cursor;
355
+ }
356
+ linesToDelete.add(cursor);
357
+ }
358
+ return;
359
+ };
360
+ const endingCursorLines = [];
361
+ for (const selection of selections) {
362
+ const lineNumber = selection.startLineNumber;
363
+ endingCursorLines.push(deleteDown(lineNumber));
364
+ deleteUp(lineNumber);
365
+ for (let inner = selection.startLineNumber; inner <= selection.endLineNumber; inner++) {
366
+ linesToDelete.add(inner);
367
+ }
368
+ }
369
+ if (endingCursorLines.length === 0) {
370
+ endingCursorLines.push(1);
371
+ }
372
+ const isDefined = (x) => x !== undefined;
373
+ model.pushEditOperations(this.searchResultEditor.getSelections(), ( [...linesToDelete].map(line => ({ range: ( new Range(line, 1, line + 1, 1)), text: '' }))), () => ( endingCursorLines.filter(isDefined).map(line => ( new Selection(line, 1, line, 1)))));
374
+ }
375
+ cleanState() {
376
+ this.getInput()?.setDirty(false);
377
+ }
378
+ get searchConfig() {
379
+ return this.configurationService.getValue('search');
380
+ }
381
+ iterateThroughMatches(reverse) {
382
+ const model = this.searchResultEditor.getModel();
383
+ if (!model) {
384
+ return;
385
+ }
386
+ const lastLine = model.getLineCount() ?? 1;
387
+ const lastColumn = model.getLineLength(lastLine);
388
+ const fallbackStart = reverse ? ( new Position(lastLine, lastColumn)) : ( new Position(1, 1));
389
+ const currentPosition = this.searchResultEditor.getSelection()?.getStartPosition() ?? fallbackStart;
390
+ const matchRanges = this.getInput()?.getMatchRanges();
391
+ if (!matchRanges) {
392
+ return;
393
+ }
394
+ const matchRange = (reverse ? findPrevRange : findNextRange)(matchRanges, currentPosition);
395
+ this.searchResultEditor.setSelection(matchRange);
396
+ this.searchResultEditor.revealLineInCenterIfOutsideViewport(matchRange.startLineNumber);
397
+ this.searchResultEditor.focus();
398
+ const matchLineText = model.getLineContent(matchRange.startLineNumber);
399
+ const matchText = model.getValueInRange(matchRange);
400
+ let file = '';
401
+ for (let line = matchRange.startLineNumber; line >= 1; line--) {
402
+ const lineText = model.getValueInRange(( new Range(line, 1, line, 2)));
403
+ if (lineText !== ' ') {
404
+ file = model.getLineContent(line);
405
+ break;
406
+ }
407
+ }
408
+ alert(( localizeWithPath(
409
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
410
+ 'searchResultItem',
411
+ "Matched {0} at {1} in file {2}",
412
+ matchText,
413
+ matchLineText,
414
+ file.slice(0, file.length - 1)
415
+ )));
416
+ }
417
+ focusNextResult() {
418
+ this.iterateThroughMatches(false);
419
+ }
420
+ focusPreviousResult() {
421
+ this.iterateThroughMatches(true);
422
+ }
423
+ focusAllResults() {
424
+ this.searchResultEditor
425
+ .setSelections(( (this.getInput()?.getMatchRanges() ?? []).map(range => ( new Selection(
426
+ range.startLineNumber,
427
+ range.startColumn,
428
+ range.endLineNumber,
429
+ range.endColumn
430
+ )))));
431
+ this.searchResultEditor.focus();
432
+ }
433
+ async triggerSearch(_options) {
434
+ const options = { resetCursor: true, delay: 0, ..._options };
435
+ if (!this.pauseSearching) {
436
+ await this.runSearchDelayer.trigger(async () => {
437
+ this.toggleRunAgainMessage(false);
438
+ await this.doRunSearch();
439
+ if (options.resetCursor) {
440
+ this.searchResultEditor.setPosition(( new Position(1, 1)));
441
+ this.searchResultEditor.setScrollPosition({ scrollTop: 0, scrollLeft: 0 });
442
+ }
443
+ if (options.focusResults) {
444
+ this.searchResultEditor.focus();
445
+ }
446
+ }, options.delay);
447
+ }
448
+ }
449
+ readConfigFromWidget() {
450
+ return {
451
+ isCaseSensitive: this.queryEditorWidget.searchInput?.getCaseSensitive() ?? false,
452
+ contextLines: this.queryEditorWidget.getContextLines(),
453
+ filesToExclude: this.inputPatternExcludes.getValue(),
454
+ filesToInclude: this.inputPatternIncludes.getValue(),
455
+ query: this.queryEditorWidget.searchInput?.getValue() ?? '',
456
+ isRegexp: this.queryEditorWidget.searchInput?.getRegex() ?? false,
457
+ matchWholeWord: this.queryEditorWidget.searchInput?.getWholeWords() ?? false,
458
+ useExcludeSettingsAndIgnoreFiles: this.inputPatternExcludes.useExcludesAndIgnoreFiles(),
459
+ onlyOpenEditors: this.inputPatternIncludes.onlySearchInOpenEditors(),
460
+ showIncludesExcludes: this.showingIncludesExcludes,
461
+ notebookSearchConfig: {
462
+ includeMarkupInput: this.queryEditorWidget.getNotebookFilters().markupInput,
463
+ includeMarkupPreview: this.queryEditorWidget.getNotebookFilters().markupPreview,
464
+ includeCodeInput: this.queryEditorWidget.getNotebookFilters().codeInput,
465
+ includeOutput: this.queryEditorWidget.getNotebookFilters().codeOutput,
466
+ }
467
+ };
468
+ }
469
+ async doRunSearch() {
470
+ this.searchModel.cancelSearch(true);
471
+ const startInput = this.getInput();
472
+ if (!startInput) {
473
+ return;
474
+ }
475
+ this.searchHistoryDelayer.trigger(() => {
476
+ this.queryEditorWidget.searchInput?.onSearchSubmit();
477
+ this.inputPatternExcludes.onSearchSubmit();
478
+ this.inputPatternIncludes.onSearchSubmit();
479
+ });
480
+ const config = this.readConfigFromWidget();
481
+ if (!config.query) {
482
+ return;
483
+ }
484
+ const content = {
485
+ pattern: config.query,
486
+ isRegExp: config.isRegexp,
487
+ isCaseSensitive: config.isCaseSensitive,
488
+ isWordMatch: config.matchWholeWord,
489
+ };
490
+ const options = {
491
+ _reason: 'searchEditor',
492
+ extraFileResources: this.instantiationService.invokeFunction(getOutOfWorkspaceEditorResources),
493
+ maxResults: this.searchConfig.maxResults ?? undefined,
494
+ disregardIgnoreFiles: !config.useExcludeSettingsAndIgnoreFiles || undefined,
495
+ disregardExcludeSettings: !config.useExcludeSettingsAndIgnoreFiles || undefined,
496
+ excludePattern: config.filesToExclude,
497
+ includePattern: config.filesToInclude,
498
+ onlyOpenEditors: config.onlyOpenEditors,
499
+ previewOptions: {
500
+ matchLines: 1,
501
+ charsPerLine: 1000
502
+ },
503
+ afterContext: config.contextLines,
504
+ beforeContext: config.contextLines,
505
+ isSmartCase: this.searchConfig.smartCase,
506
+ expandPatterns: true,
507
+ notebookSearchConfig: {
508
+ includeMarkupInput: config.notebookSearchConfig.includeMarkupInput,
509
+ includeMarkupPreview: config.notebookSearchConfig.includeMarkupPreview,
510
+ includeCodeInput: config.notebookSearchConfig.includeCodeInput,
511
+ includeOutput: config.notebookSearchConfig.includeOutput,
512
+ }
513
+ };
514
+ const folderResources = this.contextService.getWorkspace().folders;
515
+ let query;
516
+ try {
517
+ const queryBuilder = this.instantiationService.createInstance(QueryBuilder);
518
+ query = queryBuilder.text(content, ( folderResources.map(folder => folder.uri)), options);
519
+ }
520
+ catch (err) {
521
+ return;
522
+ }
523
+ this.searchOperation.start(500);
524
+ this.ongoingOperations++;
525
+ const { configurationModel } = await startInput.resolveModels();
526
+ configurationModel.updateConfig(config);
527
+ const result = this.searchModel.search(query);
528
+ startInput.ongoingSearchOperation = result.asyncResults.finally(() => {
529
+ this.ongoingOperations--;
530
+ if (this.ongoingOperations === 0) {
531
+ this.searchOperation.stop();
532
+ }
533
+ });
534
+ const searchOperation = await startInput.ongoingSearchOperation;
535
+ await this.onSearchComplete(searchOperation, config, startInput);
536
+ }
537
+ async onSearchComplete(searchOperation, startConfig, startInput) {
538
+ const input = this.getInput();
539
+ if (!input ||
540
+ input !== startInput ||
541
+ JSON.stringify(startConfig) !== JSON.stringify(this.readConfigFromWidget())) {
542
+ return;
543
+ }
544
+ input.ongoingSearchOperation = undefined;
545
+ const sortOrder = this.searchConfig.sortOrder;
546
+ if (sortOrder === "modified" ) {
547
+ await this.retrieveFileStats(this.searchModel.searchResult);
548
+ }
549
+ const controller = ReferencesController.get(this.searchResultEditor);
550
+ controller?.closeWidget(false);
551
+ const labelFormatter = (uri) => this.labelService.getUriLabel(uri, { relative: true });
552
+ const results = serializeSearchResultForEditor(this.searchModel.searchResult, startConfig.filesToInclude, startConfig.filesToExclude, startConfig.contextLines, labelFormatter, sortOrder, searchOperation?.limitHit);
553
+ const { resultsModel } = await input.resolveModels();
554
+ this.updatingModelForSearch = true;
555
+ this.modelService.updateModel(resultsModel, results.text);
556
+ this.updatingModelForSearch = false;
557
+ if (searchOperation && searchOperation.messages) {
558
+ for (const message of searchOperation.messages) {
559
+ this.addMessage(message);
560
+ }
561
+ }
562
+ this.reLayout();
563
+ input.setDirty(!input.hasCapability(4 ));
564
+ input.setMatchRanges(results.matchRanges);
565
+ }
566
+ addMessage(message) {
567
+ let messageBox;
568
+ if (this.messageBox.firstChild) {
569
+ messageBox = this.messageBox.firstChild;
570
+ }
571
+ else {
572
+ messageBox = append(this.messageBox, $('.message'));
573
+ }
574
+ append(messageBox, renderSearchMessage(message, this.instantiationService, this.notificationService, this.openerService, this.commandService, this.messageDisposables, () => this.triggerSearch()));
575
+ }
576
+ async retrieveFileStats(searchResult) {
577
+ const files = ( searchResult.matches().filter(f => !f.fileStat).map(f => f.resolveFileStat(this.fileService)));
578
+ await Promise.all(files);
579
+ }
580
+ layout(dimension) {
581
+ this.dimension = dimension;
582
+ this.reLayout();
583
+ }
584
+ getSelected() {
585
+ const selection = this.searchResultEditor.getSelection();
586
+ if (selection) {
587
+ return this.searchResultEditor.getModel()?.getValueInRange(selection) ?? '';
588
+ }
589
+ return '';
590
+ }
591
+ reLayout() {
592
+ if (this.dimension) {
593
+ this.queryEditorWidget.setWidth(this.dimension.width - 28 );
594
+ this.searchResultEditor.layout({ height: this.dimension.height - getTotalHeight(this.queryEditorContainer), width: this.dimension.width });
595
+ this.inputPatternExcludes.setWidth(this.dimension.width - 28 );
596
+ this.inputPatternIncludes.setWidth(this.dimension.width - 28 );
597
+ }
598
+ }
599
+ getInput() {
600
+ return this.input;
601
+ }
602
+ setSearchConfig(config) {
603
+ this.priorConfig = config;
604
+ if (config.query !== undefined) {
605
+ this.queryEditorWidget.setValue(config.query);
606
+ }
607
+ if (config.isCaseSensitive !== undefined) {
608
+ this.queryEditorWidget.searchInput?.setCaseSensitive(config.isCaseSensitive);
609
+ }
610
+ if (config.isRegexp !== undefined) {
611
+ this.queryEditorWidget.searchInput?.setRegex(config.isRegexp);
612
+ }
613
+ if (config.matchWholeWord !== undefined) {
614
+ this.queryEditorWidget.searchInput?.setWholeWords(config.matchWholeWord);
615
+ }
616
+ if (config.contextLines !== undefined) {
617
+ this.queryEditorWidget.setContextLines(config.contextLines);
618
+ }
619
+ if (config.filesToExclude !== undefined) {
620
+ this.inputPatternExcludes.setValue(config.filesToExclude);
621
+ }
622
+ if (config.filesToInclude !== undefined) {
623
+ this.inputPatternIncludes.setValue(config.filesToInclude);
624
+ }
625
+ if (config.onlyOpenEditors !== undefined) {
626
+ this.inputPatternIncludes.setOnlySearchInOpenEditors(config.onlyOpenEditors);
627
+ }
628
+ if (config.useExcludeSettingsAndIgnoreFiles !== undefined) {
629
+ this.inputPatternExcludes.setUseExcludesAndIgnoreFiles(config.useExcludeSettingsAndIgnoreFiles);
630
+ }
631
+ if (config.showIncludesExcludes !== undefined) {
632
+ this.toggleIncludesExcludes(config.showIncludesExcludes);
633
+ }
634
+ }
635
+ async setInput(newInput, options, context, token) {
636
+ await super.setInput(newInput, options, context, token);
637
+ if (token.isCancellationRequested) {
638
+ return;
639
+ }
640
+ const { configurationModel, resultsModel } = await newInput.resolveModels();
641
+ if (token.isCancellationRequested) {
642
+ return;
643
+ }
644
+ this.searchResultEditor.setModel(resultsModel);
645
+ this.pauseSearching = true;
646
+ this.toggleRunAgainMessage(!newInput.ongoingSearchOperation && resultsModel.getLineCount() === 1 && resultsModel.getValueLength() === 0 && configurationModel.config.query !== '');
647
+ this.setSearchConfig(configurationModel.config);
648
+ this._register(configurationModel.onConfigDidUpdate(newConfig => {
649
+ if (newConfig !== this.priorConfig) {
650
+ this.pauseSearching = true;
651
+ this.setSearchConfig(newConfig);
652
+ this.pauseSearching = false;
653
+ }
654
+ }));
655
+ this.restoreViewState(context);
656
+ if (!options?.preserveFocus) {
657
+ this.focus();
658
+ }
659
+ this.pauseSearching = false;
660
+ if (newInput.ongoingSearchOperation) {
661
+ const existingConfig = this.readConfigFromWidget();
662
+ newInput.ongoingSearchOperation.then(complete => {
663
+ this.onSearchComplete(complete, existingConfig, newInput);
664
+ });
665
+ }
666
+ }
667
+ toggleIncludesExcludes(_shouldShow) {
668
+ const cls = 'expanded';
669
+ const shouldShow = _shouldShow ?? !this.includesExcludesContainer.classList.contains(cls);
670
+ if (shouldShow) {
671
+ this.toggleQueryDetailsButton.setAttribute('aria-expanded', 'true');
672
+ this.includesExcludesContainer.classList.add(cls);
673
+ }
674
+ else {
675
+ this.toggleQueryDetailsButton.setAttribute('aria-expanded', 'false');
676
+ this.includesExcludesContainer.classList.remove(cls);
677
+ }
678
+ this.showingIncludesExcludes = this.includesExcludesContainer.classList.contains(cls);
679
+ this.reLayout();
680
+ }
681
+ toEditorViewStateResource(input) {
682
+ if (input.typeId === SearchEditorInputTypeId) {
683
+ return input.modelUri;
684
+ }
685
+ return undefined;
686
+ }
687
+ computeEditorViewState(resource) {
688
+ const control = this.getControl();
689
+ const editorViewState = control.saveViewState();
690
+ if (!editorViewState) {
691
+ return undefined;
692
+ }
693
+ if (( resource.toString()) !== this.getInput()?.modelUri.toString()) {
694
+ return undefined;
695
+ }
696
+ return { ...editorViewState, focused: this.searchResultEditor.hasWidgetFocus() ? 'editor' : 'input' };
697
+ }
698
+ tracksEditorViewState(input) {
699
+ return input.typeId === SearchEditorInputTypeId;
700
+ }
701
+ restoreViewState(context) {
702
+ const viewState = this.loadEditorViewState(this.getInput(), context);
703
+ if (viewState) {
704
+ this.searchResultEditor.restoreViewState(viewState);
705
+ }
706
+ }
707
+ getAriaLabel() {
708
+ return this.getInput()?.getName() ?? ( localizeWithPath(
709
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
710
+ 'searchEditor',
711
+ "Search"
712
+ ));
713
+ }
714
+ };
715
+ SearchEditor = SearchEditor_1 = ( __decorate([
716
+ ( __param(1, ITelemetryService)),
717
+ ( __param(2, IThemeService)),
718
+ ( __param(3, IStorageService)),
719
+ ( __param(4, IModelService)),
720
+ ( __param(5, IWorkspaceContextService)),
721
+ ( __param(6, ILabelService)),
722
+ ( __param(7, IInstantiationService)),
723
+ ( __param(8, IContextViewService)),
724
+ ( __param(9, ICommandService)),
725
+ ( __param(10, IOpenerService)),
726
+ ( __param(11, INotificationService)),
727
+ ( __param(12, IEditorProgressService)),
728
+ ( __param(13, ITextResourceConfigurationService)),
729
+ ( __param(14, IEditorGroupsService)),
730
+ ( __param(15, IEditorService)),
731
+ ( __param(16, IConfigurationService)),
732
+ ( __param(17, IFileService)),
733
+ ( __param(18, ILogService))
734
+ ], SearchEditor));
735
+ const searchEditorTextInputBorder = registerColor('searchEditor.textInputBorder', { dark: inputBorder, light: inputBorder, hcDark: inputBorder, hcLight: inputBorder }, ( localizeWithPath(
736
+ 'vs/workbench/contrib/searchEditor/browser/searchEditor',
737
+ 'textInputBoxBorder',
738
+ "Search editor text input box border."
739
+ )));
740
+ function findNextRange(matchRanges, currentPosition) {
741
+ for (const matchRange of matchRanges) {
742
+ if (Position.isBefore(currentPosition, matchRange.getStartPosition())) {
743
+ return matchRange;
744
+ }
745
+ }
746
+ return matchRanges[0];
747
+ }
748
+ function findPrevRange(matchRanges, currentPosition) {
749
+ for (let i = matchRanges.length - 1; i >= 0; i--) {
750
+ const matchRange = matchRanges[i];
751
+ if (Position.isBefore(matchRange.getStartPosition(), currentPosition)) {
752
+ {
753
+ return matchRange;
754
+ }
755
+ }
756
+ }
757
+ return matchRanges[matchRanges.length - 1];
758
+ }
759
+
760
+ export { SearchEditor };