searchEditor.ts 21.6 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6 7
import * as DOM from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
8
import { Delayer } from 'vs/base/common/async';
9 10
import { CancellationToken } from 'vs/base/common/cancellation';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
11
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
12 13 14 15
import { URI } from 'vs/base/common/uri';
import 'vs/css!./media/searchEditor';
import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
import type { IEditorOptions } from 'vs/editor/common/config/editorOptions';
16
import { Range } from 'vs/editor/common/core/range';
J
Jackson Kearl 已提交
17
import { TrackedRangeStickiness } from 'vs/editor/common/model';
18
import { IModelService } from 'vs/editor/common/services/modelService';
19
import { ReferencesController } from 'vs/editor/contrib/gotoSymbol/peek/referencesController';
20 21
import { localize } from 'vs/nls';
import { ICommandService } from 'vs/platform/commands/common/commands';
22
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
23
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
24 25 26
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILabelService } from 'vs/platform/label/common/label';
27
import { IEditorProgressService, LongRunningOperation } from 'vs/platform/progress/common/progress';
28 29
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
30 31
import { inputBorder, registerColor, searchEditorFindMatch, searchEditorFindMatchBorder } from 'vs/platform/theme/common/colorRegistry';
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
32
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
33 34
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
35
import { EditorOptions } from 'vs/workbench/common/editor';
36 37
import { ExcludePatternInputWidget, PatternInputWidget } from 'vs/workbench/contrib/search/browser/patternInputWidget';
import { SearchWidget } from 'vs/workbench/contrib/search/browser/searchWidget';
38
import { InputBoxFocusedKey } from 'vs/workbench/contrib/search/common/constants';
39 40
import { ITextQueryBuilderOptions, QueryBuilder } from 'vs/workbench/contrib/search/common/queryBuilder';
import { getOutOfWorkspaceEditorResources } from 'vs/workbench/contrib/search/common/search';
J
Jackson Kearl 已提交
41
import { SearchModel } from 'vs/workbench/contrib/search/common/searchModel';
42
import { InSearchEditor } from 'vs/workbench/contrib/searchEditor/browser/constants';
43 44 45
import type { SearchConfiguration, SearchEditorInput } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import { extractSearchQuery, serializeSearchConfiguration, serializeSearchResultForEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
import { IPatternInfo, ISearchConfigurationProperties, ITextQuery } from 'vs/workbench/services/search/common/search';
46
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
47 48

const RESULT_LINE_REGEX = /^(\s+)(\d+)(:| )(\s+)(.*)$/;
49
const FILE_LINE_REGEX = /^(\S.*):$/;
50 51 52 53 54 55 56 57 58 59 60 61

export class SearchEditor extends BaseEditor {
	static readonly ID: string = 'workbench.editor.searchEditor';

	private queryEditorWidget!: SearchWidget;
	private searchResultEditor!: CodeEditorWidget;
	private queryEditorContainer!: HTMLElement;
	private dimension?: DOM.Dimension;
	private inputPatternIncludes!: PatternInputWidget;
	private inputPatternExcludes!: ExcludePatternInputWidget;
	private includesExcludesContainer!: HTMLElement;
	private toggleQueryDetailsButton!: HTMLElement;
62
	private messageBox!: HTMLElement;
63 64 65

	private runSearchDelayer = new Delayer(300);
	private pauseSearching: boolean = false;
66
	private showingIncludesExcludes: boolean = false;
67 68
	private inSearchEditorContextKey: IContextKey<boolean>;
	private inputFocusContextKey: IContextKey<boolean>;
69
	private searchOperation: LongRunningOperation;
J
Jackson Kearl 已提交
70
	private searchHistoryDelayer: Delayer<void>;
71
	private messageDisposables: IDisposable[] = [];
72
	private container: HTMLElement;
73 74 75 76 77 78 79 80 81

	constructor(
		@ITelemetryService telemetryService: ITelemetryService,
		@IThemeService themeService: IThemeService,
		@IStorageService storageService: IStorageService,
		@IModelService private readonly modelService: IModelService,
		@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
		@ILabelService private readonly labelService: ILabelService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
82
		@IInstantiationService readonly instantiationService: IInstantiationService,
83 84
		@IContextViewService private readonly contextViewService: IContextViewService,
		@ICommandService private readonly commandService: ICommandService,
85
		@IContextKeyService readonly contextKeyService: IContextKeyService,
86
		@IEditorProgressService readonly progressService: IEditorProgressService,
87 88
	) {
		super(SearchEditor.ID, telemetryService, themeService, storageService);
89 90 91 92 93 94 95 96
		this.container = DOM.$('.search-editor');

		const scopedContextKeyService = contextKeyService.createScoped(this.container);
		this.instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService]));

		this.inSearchEditorContextKey = InSearchEditor.bindTo(scopedContextKeyService);
		this.inSearchEditorContextKey.set(true);
		this.inputFocusContextKey = InputBoxFocusedKey.bindTo(scopedContextKeyService);
97
		this.searchOperation = this._register(new LongRunningOperation(progressService));
J
Jackson Kearl 已提交
98
		this.searchHistoryDelayer = new Delayer<void>(2000);
99 100 101
	}

	createEditor(parent: HTMLElement) {
102
		DOM.append(parent, this.container);
103

104 105
		this.createQueryEditor(this.container);
		this.createResultsEditor(this.container);
106
	}
107

108 109
	private createQueryEditor(parent: HTMLElement) {
		this.queryEditorContainer = DOM.append(parent, DOM.$('.query-container'));
110 111 112
		this.queryEditorWidget = this._register(this.instantiationService.createInstance(SearchWidget, this.queryEditorContainer, { _hideReplaceToggle: true, showContextToggle: true }));
		this._register(this.queryEditorWidget.onReplaceToggled(() => this.reLayout()));
		this._register(this.queryEditorWidget.onDidHeightChange(() => this.reLayout()));
J
Jackson Kearl 已提交
113 114 115
		this.queryEditorWidget.onSearchSubmit(() => this.runSearch(true, true)); // onSearchSubmit has an internal delayer, so skip over ours.
		this.queryEditorWidget.searchInput.onDidOptionChange(() => this.runSearch(false));
		this.queryEditorWidget.onDidToggleContext(() => this.runSearch(false));
116 117 118

		// Includes/Excludes Dropdown
		this.includesExcludesContainer = DOM.append(this.queryEditorContainer, DOM.$('.includes-excludes'));
119

120 121 122 123
		// // Toggle query details button
		this.toggleQueryDetailsButton = DOM.append(this.includesExcludesContainer, DOM.$('.expand.codicon.codicon-ellipsis', { tabindex: 0, role: 'button', title: localize('moreSearch', "Toggle Search Details") }));
		this._register(DOM.addDisposableListener(this.toggleQueryDetailsButton, DOM.EventType.CLICK, e => {
			DOM.EventHelper.stop(e);
124
			this.toggleIncludesExcludes();
125 126 127 128 129
		}));
		this._register(DOM.addDisposableListener(this.toggleQueryDetailsButton, DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
			const event = new StandardKeyboardEvent(e);
			if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
				DOM.EventHelper.stop(e);
130
				this.toggleIncludesExcludes();
131 132 133 134 135 136 137
			}
		}));
		this._register(DOM.addDisposableListener(this.toggleQueryDetailsButton, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
			const event = new StandardKeyboardEvent(e);
			if (event.equals(KeyMod.Shift | KeyCode.Tab)) {
				if (this.queryEditorWidget.isReplaceActive()) {
					this.queryEditorWidget.focusReplaceAllAction();
138 139
				}
				else {
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
					this.queryEditorWidget.isReplaceShown() ? this.queryEditorWidget.replaceInput.focusOnPreserve() : this.queryEditorWidget.focusRegexAction();
				}
				DOM.EventHelper.stop(e);
			}
		}));

		// // Includes
		const folderIncludesList = DOM.append(this.includesExcludesContainer, DOM.$('.file-types.includes'));
		const filesToIncludeTitle = localize('searchScope.includes', "files to include");
		DOM.append(folderIncludesList, DOM.$('h4', undefined, filesToIncludeTitle));
		this.inputPatternIncludes = this._register(this.instantiationService.createInstance(PatternInputWidget, folderIncludesList, this.contextViewService, {
			ariaLabel: localize('label.includes', 'Search Include Patterns'),
		}));
		this.inputPatternIncludes.onSubmit(_triggeredOnType => this.runSearch());

		// // Excludes
		const excludesList = DOM.append(this.includesExcludesContainer, DOM.$('.file-types.excludes'));
		const excludesTitle = localize('searchScope.excludes', "files to exclude");
		DOM.append(excludesList, DOM.$('h4', undefined, excludesTitle));
		this.inputPatternExcludes = this._register(this.instantiationService.createInstance(ExcludePatternInputWidget, excludesList, this.contextViewService, {
			ariaLabel: localize('label.excludes', 'Search Exclude Patterns'),
		}));
		this.inputPatternExcludes.onSubmit(_triggeredOnType => this.runSearch());
		this.inputPatternExcludes.onChangeIgnoreBox(() => this.runSearch());
164 165 166

		[this.queryEditorWidget.searchInput, this.inputPatternIncludes, this.inputPatternExcludes].map(input =>
			this._register(attachInputBoxStyler(input, this.themeService, { inputBorder: searchEditorTextInputBorder })));
167 168 169 170 171 172 173 174 175 176 177 178

		// Messages
		this.messageBox = DOM.append(this.queryEditorContainer, DOM.$('.messages'));
	}


	private toggleRunAgainMessage(show: boolean) {
		DOM.clearNode(this.messageBox);
		dispose(this.messageDisposables);
		this.messageDisposables = [];

		if (show) {
J
Naming  
Jackson Kearl 已提交
179
			const runAgainLink = DOM.append(this.messageBox, DOM.$('a.pointer.prominent.message', {}, localize('runSearch', "Run Search")));
180 181 182 183 184
			this.messageDisposables.push(DOM.addDisposableListener(runAgainLink, DOM.EventType.CLICK, async () => {
				await this.runSearch(true, true);
				this.toggleRunAgainMessage(false);
			}));
		}
185
	}
186

187
	private createResultsEditor(parent: HTMLElement) {
188
		const searchResultContainer = DOM.append(parent, DOM.$('.search-results'));
189 190 191 192 193 194 195 196
		const getSearchEditorOptions = () => this.configurationService.getValue<IEditorOptions>('editor', { overrideIdentifier: 'search-result' });
		const configuration: IEditorOptions = getSearchEditorOptions();
		this._register(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('editor')) {
				this.searchResultEditor.updateOptions(getSearchEditorOptions());
			}
		}));

197 198 199 200 201 202 203 204 205 206 207 208
		const options: ICodeEditorWidgetOptions = {};
		this.searchResultEditor = this._register(this.instantiationService.createInstance(CodeEditorWidget, searchResultContainer, configuration, options));
		this.searchResultEditor.onMouseUp(e => {

			if (e.event.detail === 2) {
				const behaviour = this.configurationService.getValue<ISearchConfigurationProperties>('search').searchEditorPreview.doubleClickBehaviour;
				const position = e.target.position;
				if (position && behaviour !== 'selectWord') {
					const line = this.searchResultEditor.getModel()?.getLineContent(position.lineNumber) ?? '';
					if (line.match(RESULT_LINE_REGEX)) {
						this.searchResultEditor.setSelection(Range.fromPositions(position));
						this.commandService.executeCommand(behaviour === 'goToLocation' ? 'editor.action.goToDeclaration' : 'editor.action.openDeclarationToTheSide');
209 210 211
					} else if (line.match(FILE_LINE_REGEX)) {
						this.searchResultEditor.setSelection(Range.fromPositions(position));
						this.commandService.executeCommand('editor.action.peekDefinition');
212 213 214 215
					}
				}
			}
		});
216

J
Jackson Kearl 已提交
217
		this._register(this.onDidBlur(() => this.saveViewState()));
J
Jackson Kearl 已提交
218

219 220
		this._register(this.searchResultEditor.onKeyDown(e => e.keyCode === KeyCode.Escape && this.queryEditorWidget.searchInput.focus()));

221
		this._register(this.searchResultEditor.onDidChangeModelContent(() => this.getInput()?.setDirty(true)));
222 223 224 225 226 227 228 229

		[this.queryEditorWidget.searchInputFocusTracker, this.queryEditorWidget.replaceInputFocusTracker, this.inputPatternExcludes.inputFocusTracker, this.inputPatternIncludes.inputFocusTracker]
			.map(tracker => {
				this._register(tracker.onDidFocus(() => setTimeout(() => this.inputFocusContextKey.set(true), 0)));
				this._register(tracker.onDidBlur(() => this.inputFocusContextKey.set(false)));
			});
	}

J
Jackson Kearl 已提交
230 231 232 233 234

	getControl() {
		return this.searchResultEditor;
	}

J
Jackson Kearl 已提交
235
	focus() {
J
Jackson Kearl 已提交
236 237 238 239 240 241
		const input = this.getInput();
		if (input && input.viewState && input.viewState.focused === 'editor') {
			this.searchResultEditor.focus();
		} else {
			this.queryEditorWidget.focus();
		}
J
Jackson Kearl 已提交
242 243
	}

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
	focusNextInput() {
		if (this.queryEditorWidget.searchInputHasFocus()) {
			if (this.showingIncludesExcludes) {
				this.inputPatternIncludes.focus();
			} else {
				this.searchResultEditor.focus();
			}
		} else if (this.inputPatternIncludes.inputHasFocus()) {
			this.inputPatternExcludes.focus();
		} else if (this.inputPatternExcludes.inputHasFocus()) {
			this.searchResultEditor.focus();
		} else if (this.searchResultEditor.hasWidgetFocus()) {
			// pass
		}
	}

	focusPrevInput() {
		if (this.queryEditorWidget.searchInputHasFocus()) {
			this.searchResultEditor.focus(); // wrap
		} else if (this.inputPatternIncludes.inputHasFocus()) {
			this.queryEditorWidget.searchInput.focus();
		} else if (this.inputPatternExcludes.inputHasFocus()) {
			this.inputPatternIncludes.focus();
		} else if (this.searchResultEditor.hasWidgetFocus()) {
J
Jackson Kearl 已提交
268
			// unreachable.
269
		}
270 271
	}

272 273
	toggleWholeWords() {
		this.queryEditorWidget.searchInput.setWholeWords(!this.queryEditorWidget.searchInput.getWholeWords());
J
Jackson Kearl 已提交
274
		this.runSearch(false);
275 276 277 278
	}

	toggleRegex() {
		this.queryEditorWidget.searchInput.setRegex(!this.queryEditorWidget.searchInput.getRegex());
J
Jackson Kearl 已提交
279
		this.runSearch(false);
280 281 282 283
	}

	toggleCaseSensitive() {
		this.queryEditorWidget.searchInput.setCaseSensitive(!this.queryEditorWidget.searchInput.getCaseSensitive());
J
Jackson Kearl 已提交
284
		this.runSearch(false);
285 286
	}

287 288 289 290
	toggleContextLines() {
		this.queryEditorWidget.toggleContextLines();
	}

291 292 293 294
	toggleQueryDetails() {
		this.toggleIncludesExcludes();
	}

J
Jackson Kearl 已提交
295
	async runSearch(resetCursor = true, instant = false) {
296
		if (!this.pauseSearching) {
297
			await this.runSearchDelayer.trigger(async () => {
J
Jackson Kearl 已提交
298 299 300 301 302
				await this.doRunSearch();
				if (resetCursor) {
					this.searchResultEditor.setSelection(new Range(1, 1, 1, 1));
				}
			}, instant ? 0 : undefined);
303 304 305 306 307 308
		}
	}

	private async doRunSearch() {
		const startInput = this.input;

J
Jackson Kearl 已提交
309 310 311 312 313 314
		this.searchHistoryDelayer.trigger(() => {
			this.queryEditorWidget.searchInput.onSearchSubmit();
			this.inputPatternExcludes.onSearchSubmit();
			this.inputPatternIncludes.onSearchSubmit();
		});

315 316 317 318 319 320 321 322
		const config: SearchConfiguration = {
			caseSensitive: this.queryEditorWidget.searchInput.getCaseSensitive(),
			contextLines: this.queryEditorWidget.contextLines(),
			excludes: this.inputPatternExcludes.getValue(),
			includes: this.inputPatternIncludes.getValue(),
			query: this.queryEditorWidget.searchInput.getValue(),
			regexp: this.queryEditorWidget.searchInput.getRegex(),
			wholeWord: this.queryEditorWidget.searchInput.getWholeWords(),
323 324
			useIgnores: this.inputPatternExcludes.useExcludesAndIgnoreFiles(),
			showIncludesExcludes: this.showingIncludesExcludes
325 326
		};

327 328
		if (!config.query) { return; }

329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
		const content: IPatternInfo = {
			pattern: config.query,
			isRegExp: config.regexp,
			isCaseSensitive: config.caseSensitive,
			isWordMatch: config.wholeWord,
		};

		const options: ITextQueryBuilderOptions = {
			_reason: 'searchEditor',
			extraFileResources: this.instantiationService.invokeFunction(getOutOfWorkspaceEditorResources),
			maxResults: 10000,
			disregardIgnoreFiles: !config.useIgnores,
			disregardExcludeSettings: !config.useIgnores,
			excludePattern: config.excludes,
			includePattern: config.includes,
			previewOptions: {
				matchLines: 1,
				charsPerLine: 1000
			},
			afterContext: config.contextLines,
			beforeContext: config.contextLines,
			isSmartCase: this.configurationService.getValue<ISearchConfigurationProperties>('search').smartCase,
			expandPatterns: true
		};

		const folderResources = this.contextService.getWorkspace().folders;
		let query: ITextQuery;
		try {
			const queryBuilder = this.instantiationService.createInstance(QueryBuilder);
			query = queryBuilder.text(content, folderResources.map(folder => folder.uri), options);
		}
		catch (err) {
			return;
		}
		const searchModel = this.instantiationService.createInstance(SearchModel);
364 365
		this.searchOperation.start(500);
		await searchModel.search(query).finally(() => this.searchOperation.stop());
J
Jackson Kearl 已提交
366 367
		const input = this.getInput();
		if (!input || input !== startInput) {
368 369 370 371
			searchModel.dispose();
			return;
		}

372 373
		const controller = ReferencesController.get(this.searchResultEditor);
		controller.closeWidget(false);
374
		const labelFormatter = (uri: URI): string => this.labelService.getUriLabel(uri, { relative: true });
375
		const results = serializeSearchResultForEditor(searchModel.searchResult, config.includes, config.excludes, config.contextLines, labelFormatter, false);
J
Jackson Kearl 已提交
376
		const { header, body } = await input.getModels();
377 378
		this.modelService.updateModel(body, results.text);
		header.setValue(serializeSearchConfiguration(config));
379

J
Jackson Kearl 已提交
380 381 382
		input.setDirty(input.resource.scheme !== 'search-editor');
		input.setHighlights(results.matchRanges.map(range =>
			({ range, options: { className: 'searchEditorFindMatch', stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges } })));
383

384 385 386 387 388 389 390 391
		searchModel.dispose();
	}

	layout(dimension: DOM.Dimension) {
		this.dimension = dimension;
		this.reLayout();
	}

392 393 394 395 396 397 398 399
	getSelected() {
		const selection = this.searchResultEditor.getSelection();
		if (selection) {
			return this.searchResultEditor.getModel()?.getValueInRange(selection) ?? '';
		}
		return '';
	}

400 401 402 403 404 405 406 407 408
	private reLayout() {
		if (this.dimension) {
			this.queryEditorWidget.setWidth(this.dimension.width - 28 /* container margin */);
			this.searchResultEditor.layout({ height: this.dimension.height - DOM.getTotalHeight(this.queryEditorContainer), width: this.dimension.width });
			this.inputPatternExcludes.setWidth(this.dimension.width - 28 /* container margin */);
			this.inputPatternIncludes.setWidth(this.dimension.width - 28 /* container margin */);
		}
	}

J
Jackson Kearl 已提交
409 410 411 412
	private getInput(): SearchEditorInput | undefined {
		return this._input as SearchEditorInput;
	}

413
	async setInput(newInput: SearchEditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise<void> {
J
Jackson Kearl 已提交
414 415
		this.saveViewState();

416 417
		await super.setInput(newInput, options, token);

418
		const { body, header } = await newInput.getModels();
419

420
		this.searchResultEditor.setModel(body);
421
		this.pauseSearching = true;
422

423
		const config = extractSearchQuery(header);
424
		this.toggleRunAgainMessage(body.getLineCount() === 1 && body.getValue() === '' && config.query !== '');
425 426 427 428 429 430 431 432 433 434

		this.queryEditorWidget.setValue(config.query, true);
		this.queryEditorWidget.searchInput.setCaseSensitive(config.caseSensitive);
		this.queryEditorWidget.searchInput.setRegex(config.regexp);
		this.queryEditorWidget.searchInput.setWholeWords(config.wholeWord);
		this.queryEditorWidget.setContextLines(config.contextLines);
		this.inputPatternExcludes.setValue(config.excludes);
		this.inputPatternIncludes.setValue(config.includes);
		this.inputPatternExcludes.setUseExcludesAndIgnoreFiles(config.useIgnores);
		this.toggleIncludesExcludes(config.showIncludesExcludes);
435

J
Jackson Kearl 已提交
436
		this.restoreViewState();
437 438 439
		this.pauseSearching = false;
	}

440
	private toggleIncludesExcludes(_shouldShow?: boolean): void {
441
		const cls = 'expanded';
442
		const shouldShow = _shouldShow ?? !DOM.hasClass(this.includesExcludesContainer, cls);
443 444 445 446 447 448 449 450 451

		if (shouldShow) {
			this.toggleQueryDetailsButton.setAttribute('aria-expanded', 'true');
			DOM.addClass(this.includesExcludesContainer, cls);
		} else {
			this.toggleQueryDetailsButton.setAttribute('aria-expanded', 'false');
			DOM.removeClass(this.includesExcludesContainer, cls);
		}

452 453
		this.showingIncludesExcludes = DOM.hasClass(this.includesExcludesContainer, cls);

454 455 456 457 458 459
		this.reLayout();
	}

	getModel() {
		return this.searchResultEditor.getModel();
	}
460

J
Jackson Kearl 已提交
461 462 463 464 465 466
	private saveViewState() {
		const input = this.getInput();
		if (!input) { return; }

		if (this.searchResultEditor.hasWidgetFocus()) {
			const viewState = this.searchResultEditor.saveViewState();
467 468 469
			if (viewState) {
				input.viewState = { focused: 'editor', state: viewState };
			}
J
Jackson Kearl 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
		} else {
			input.viewState = { focused: 'input' };
		}
	}

	private restoreViewState() {
		const input = this.getInput();
		if (input && input.viewState && input.viewState.focused === 'editor') {
			this.searchResultEditor.restoreViewState(input.viewState.state);
			this.searchResultEditor.focus();
		} else {
			this.queryEditorWidget.focus();
		}
	}

485
	clearInput() {
J
Jackson Kearl 已提交
486
		this.saveViewState();
487
		super.clearInput();
488
	}
489
}
490 491 492 493 494 495 496 497 498

registerThemingParticipant((theme, collector) => {
	collector.addRule(`.monaco-editor .searchEditorFindMatch { background-color: ${theme.getColor(searchEditorFindMatch)}; }`);

	const findMatchHighlightBorder = theme.getColor(searchEditorFindMatchBorder);
	if (findMatchHighlightBorder) {
		collector.addRule(`.monaco-editor .searchEditorFindMatch { border: 1px ${theme.type === 'hc' ? 'dotted' : 'solid'} ${findMatchHighlightBorder}; box-sizing: border-box; }`);
	}
});
499 500

export const searchEditorTextInputBorder = registerColor('searchEditor.textInputBorder', { dark: inputBorder, light: inputBorder, hc: inputBorder }, localize('textInputBoxBorder', "Search editor text input box border."));