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

Inherit from BaseTextEditor.

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