提交 571ad349 编写于 作者: J Jackson Kearl

Inherit from BaseTextEditor.

Closes #90326
Closes #90325
上级 6f1de79b
......@@ -11,15 +11,13 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
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';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { Range } from 'vs/editor/common/core/range';
import { TrackedRangeStickiness } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ReferencesController } from 'vs/editor/contrib/gotoSymbol/peek/referencesController';
import { localize } from 'vs/nls';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -31,8 +29,7 @@ import { inputBorder, registerColor, searchEditorFindMatch, searchEditorFindMatc
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorOptions, IEditorMemento } from 'vs/workbench/common/editor';
import { EditorOptions } from 'vs/workbench/common/editor';
import { ExcludePatternInputWidget, PatternInputWidget } from 'vs/workbench/contrib/search/browser/patternInputWidget';
import { SearchWidget } from 'vs/workbench/contrib/search/browser/searchWidget';
import { InputBoxFocusedKey } from 'vs/workbench/contrib/search/common/constants';
......@@ -46,19 +43,21 @@ import { IPatternInfo, ISearchConfigurationProperties, ITextQuery } from 'vs/wor
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ICodeEditorViewState } from 'vs/editor/common/editorCommon';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
import { assertIsDefined } from 'vs/base/common/types';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfigurationService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
const RESULT_LINE_REGEX = /^(\s+)(\d+)(:| )(\s+)(.*)$/;
const FILE_LINE_REGEX = /^(\S.*):$/;
type SearchEditorViewState =
| { focused: 'input' }
| { focused: 'editor', state: ICodeEditorViewState };
type SearchEditorViewState = ICodeEditorViewState & { focused: 'input' | 'editor' };
export class SearchEditor extends BaseEditor {
export class SearchEditor extends BaseTextEditor {
static readonly ID: string = 'workbench.editor.searchEditor';
static readonly TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'searchEditorViewState';
static readonly SEARCH_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'searchEditorViewState';
private queryEditorWidget!: SearchWidget;
private searchResultEditor!: CodeEditorWidget;
......@@ -80,8 +79,6 @@ export class SearchEditor extends BaseEditor {
private messageDisposables: IDisposable[] = [];
private container: HTMLElement;
private editorMemento: IEditorMemento<SearchEditorViewState>;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
......@@ -89,18 +86,19 @@ export class SearchEditor extends BaseEditor {
@IModelService private readonly modelService: IModelService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@ILabelService private readonly labelService: ILabelService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IInstantiationService readonly instantiationService: IInstantiationService,
@IContextViewService private readonly contextViewService: IContextViewService,
@ICommandService private readonly commandService: ICommandService,
@IContextKeyService readonly contextKeyService: IContextKeyService,
@IEditorProgressService readonly progressService: IEditorProgressService,
@IEditorGroupsService protected editorGroupService: IEditorGroupsService
@ITextResourceConfigurationService textResourceService: ITextResourceConfigurationService,
@IEditorGroupsService protected editorGroupService: IEditorGroupsService,
@IEditorService protected editorService: IEditorService,
@IConfigurationService protected configurationService: IConfigurationService,
) {
super(SearchEditor.ID, telemetryService, themeService, storageService);
super(SearchEditor.ID, telemetryService, instantiationService, storageService, textResourceService, themeService, editorService, editorGroupService);
this.container = DOM.$('.search-editor');
this.editorMemento = this.getEditorMemento<SearchEditorViewState>(editorGroupService, SearchEditor.TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY, 100);
const scopedContextKeyService = contextKeyService.createScoped(this.container);
this.instantiationService = instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService]));
......@@ -200,18 +198,9 @@ export class SearchEditor extends BaseEditor {
private createResultsEditor(parent: HTMLElement) {
const searchResultContainer = DOM.append(parent, DOM.$('.search-results'));
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());
}
}));
const options: ICodeEditorWidgetOptions = {};
this.searchResultEditor = this._register(this.instantiationService.createInstance(CodeEditorWidget, searchResultContainer, configuration, options));
super.createEditor(searchResultContainer);
this.searchResultEditor = super.getControl() as CodeEditorWidget;
this.searchResultEditor.onMouseUp(e => {
if (e.event.detail === 2) {
const behaviour = this.configurationService.getValue<ISearchConfigurationProperties>('search').searchEditorPreview.doubleClickBehaviour;
const position = e.target.position;
......@@ -316,16 +305,8 @@ export class SearchEditor extends BaseEditor {
}
}
private async doRunSearch() {
const startInput = this.input;
this.searchHistoryDelayer.trigger(() => {
this.queryEditorWidget.searchInput.onSearchSubmit();
this.inputPatternExcludes.onSearchSubmit();
this.inputPatternIncludes.onSearchSubmit();
});
const config: SearchConfiguration = {
private readConfigFromWidget() {
return {
caseSensitive: this.queryEditorWidget.searchInput.getCaseSensitive(),
contextLines: this.queryEditorWidget.contextLines(),
excludes: this.inputPatternExcludes.getValue(),
......@@ -336,6 +317,18 @@ export class SearchEditor extends BaseEditor {
useIgnores: this.inputPatternExcludes.useExcludesAndIgnoreFiles(),
showIncludesExcludes: this.showingIncludesExcludes
};
}
private async doRunSearch() {
const startInput = this.getInput();
this.searchHistoryDelayer.trigger(() => {
this.queryEditorWidget.searchInput.onSearchSubmit();
this.inputPatternExcludes.onSearchSubmit();
this.inputPatternIncludes.onSearchSubmit();
});
const config: SearchConfiguration = this.readConfigFromWidget();
if (!config.query) { return; }
......@@ -377,7 +370,10 @@ export class SearchEditor extends BaseEditor {
this.searchOperation.start(500);
await searchModel.search(query).finally(() => this.searchOperation.stop());
const input = this.getInput();
if (!input || input !== startInput) {
if (!input ||
input !== startInput ||
JSON.stringify(config) !== JSON.stringify(this.readConfigFromWidget())) {
searchModel.dispose();
return;
}
......@@ -473,32 +469,28 @@ export class SearchEditor extends BaseEditor {
}
private saveViewState() {
const input = this.getInput();
const group = this.group;
if (!input || !group) { return; }
const resource = this.getInput()?.resource;
if (resource) { this.saveTextEditorViewState(resource); }
}
if (this.searchResultEditor.hasWidgetFocus()) {
const viewState = this.searchResultEditor.saveViewState();
if (viewState) {
this.editorMemento.saveEditorState(group, input.resource, { focused: 'editor', state: viewState });
}
} else {
this.editorMemento.saveEditorState(group, input.resource, { focused: 'input' });
}
protected retrieveTextEditorViewState(resource: URI): SearchEditorViewState | null {
const control = this.getControl();
const editorViewState = control.saveViewState();
if (!editorViewState) { return null; }
if (resource.toString() !== this.getInput()?.resource.toString()) { return null; }
return { ...editorViewState, focused: this.searchResultEditor.hasWidgetFocus() ? 'editor' : 'input' };
}
private loadViewState() {
const group = this.group;
const input = this.getInput();
if (!input || !group) { return; }
return this.editorMemento.loadEditorState(group, input.resource);
const resource = assertIsDefined(this.input?.getResource());
return this.loadTextEditorViewState(resource) as SearchEditorViewState;
}
private restoreViewState() {
const viewState = this.loadViewState();
if (viewState) { this.searchResultEditor.restoreViewState(viewState); }
if (viewState && viewState.focused === 'editor') {
this.searchResultEditor.restoreViewState(viewState.state);
this.searchResultEditor.focus();
} else {
this.queryEditorWidget.focus();
......@@ -509,6 +501,10 @@ export class SearchEditor extends BaseEditor {
this.saveViewState();
super.clearInput();
}
getAriaLabel() {
return this.getInput()?.getName() ?? localize('searchEditor', "Search Editor");
}
}
registerThemingParticipant((theme, collector) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册