Skip to content

Commit 001fb95

Browse files
author
Jackson Kearl
committed
1 parent 1775b3a commit 001fb95

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class SearchEditor extends BaseTextEditor<SearchEditorViewState> {
9292
private container: HTMLElement;
9393
private searchModel: SearchModel;
9494
private ongoingOperations: number = 0;
95+
private updatingModelForSearch: boolean = false;
9596

9697
constructor(
9798
@ITelemetryService telemetryService: ITelemetryService,
@@ -252,8 +253,11 @@ export class SearchEditor extends BaseTextEditor<SearchEditorViewState> {
252253
}
253254
}
254255
});
255-
256-
this._register(this.searchResultEditor.onDidChangeModelContent(() => this.getInput()?.setDirty(true)));
256+
this._register(this.searchResultEditor.onDidChangeModelContent(() => {
257+
if (!this.updatingModelForSearch) {
258+
this.getInput()?.setDirty(true);
259+
}
260+
}));
257261
}
258262

259263
override getControl() {
@@ -528,7 +532,7 @@ export class SearchEditor extends BaseTextEditor<SearchEditorViewState> {
528532
this.searchOperation.start(500);
529533
this.ongoingOperations++;
530534

531-
const { configurationModel } = await startInput.getModels();
535+
const { configurationModel } = await startInput.resolveModels();
532536
configurationModel.updateConfig(config);
533537

534538
startInput.ongoingSearchOperation = this.searchModel.search(query).finally(() => {
@@ -561,8 +565,10 @@ export class SearchEditor extends BaseTextEditor<SearchEditorViewState> {
561565
controller?.closeWidget(false);
562566
const labelFormatter = (uri: URI): string => this.labelService.getUriLabel(uri, { relative: true });
563567
const results = serializeSearchResultForEditor(this.searchModel.searchResult, startConfig.filesToInclude, startConfig.filesToExclude, startConfig.contextLines, labelFormatter, sortOrder, searchOperation?.limitHit);
564-
const { resultsModel } = await input.getModels();
568+
const { resultsModel } = await input.resolveModels();
569+
this.updatingModelForSearch = true;
565570
this.modelService.updateModel(resultsModel, results.text);
571+
this.updatingModelForSearch = false;
566572

567573
if (searchOperation && searchOperation.messages) {
568574
for (const message of searchOperation.messages) {
@@ -638,7 +644,7 @@ export class SearchEditor extends BaseTextEditor<SearchEditorViewState> {
638644
return;
639645
}
640646

641-
const { configurationModel, resultsModel } = await newInput.getModels();
647+
const { configurationModel, resultsModel } = await newInput.resolveModels();
642648
if (token.isCancellationRequested) { return; }
643649

644650
this.searchResultEditor.setModel(resultsModel);

src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class SearchEditorInput extends EditorInput {
132132
}
133133

134134
override async save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<EditorInput | undefined> {
135-
if (((await this.getModels()).resultsModel).isDisposed()) { return; }
135+
if (((await this.resolveModels()).resultsModel).isDisposed()) { return; }
136136

137137
if (this.backingUri) {
138138
await this.textFileService.write(this.backingUri, await this.serializeForDisk(), options);
@@ -149,29 +149,33 @@ export class SearchEditorInput extends EditorInput {
149149
}
150150

151151
private async serializeForDisk() {
152-
const { configurationModel, resultsModel } = await this.getModels();
152+
const { configurationModel, resultsModel } = await this.resolveModels();
153153
return serializeSearchConfiguration(configurationModel.config) + '\n' + resultsModel.getValue();
154154
}
155155

156156
private configChangeListenerDisposable: IDisposable | undefined;
157157
private registerConfigChangeListeners(model: SearchConfigurationModel) {
158158
this.configChangeListenerDisposable?.dispose();
159-
160159
if (!this.isDisposed()) {
161160
this.configChangeListenerDisposable = model.onConfigDidUpdate(() => {
162-
this._onDidChangeLabel.fire();
161+
const oldName = this.getName();
162+
if (oldName !== this.getName()) {
163+
this._onDidChangeLabel.fire();
164+
}
163165
this.memento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE).searchConfig = model.config;
164166
});
165-
166167
this._register(this.configChangeListenerDisposable);
167168
}
168169
}
169170

170-
async getModels() {
171+
async resolveModels() {
171172
return this.model.resolve().then(data => {
173+
const oldName = this.getName();
172174
this._cachedResultsModel = data.resultsModel;
173175
this._cachedConfigurationModel = data.configurationModel;
174-
this._onDidChangeLabel.fire();
176+
if (oldName !== this.getName()) {
177+
this._onDidChangeLabel.fire();
178+
}
175179
this.registerConfigChangeListeners(data.configurationModel);
176180
return data;
177181
});
@@ -211,8 +215,11 @@ export class SearchEditorInput extends EditorInput {
211215
}
212216

213217
setDirty(dirty: boolean) {
218+
const wasDirty = this.dirty;
214219
this.dirty = dirty;
215-
this._onDidChangeDirty.fire();
220+
if (wasDirty !== dirty) {
221+
this._onDidChangeDirty.fire();
222+
}
216223
}
217224

218225
override isDirty() {
@@ -253,7 +260,7 @@ export class SearchEditorInput extends EditorInput {
253260
}
254261

255262
async setMatchRanges(ranges: Range[]) {
256-
this.oldDecorationsIDs = (await this.getModels()).resultsModel.deltaDecorations(this.oldDecorationsIDs, ranges.map(range =>
263+
this.oldDecorationsIDs = (await this.resolveModels()).resultsModel.deltaDecorations(this.oldDecorationsIDs, ranges.map(range =>
257264
({ range, options: { description: 'search-editor-find-match', className: SearchEditorFindMatchClass, stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges } })));
258265
}
259266

@@ -265,11 +272,11 @@ export class SearchEditorInput extends EditorInput {
265272

266273
if (this.backingUri) {
267274
const { config, text } = await this.instantiationService.invokeFunction(parseSavedSearchEditor, this.backingUri);
268-
const { resultsModel, configurationModel } = await this.getModels();
275+
const { resultsModel, configurationModel } = await this.resolveModels();
269276
resultsModel.setValue(text);
270277
configurationModel.updateConfig(config);
271278
} else {
272-
(await this.getModels()).resultsModel.setValue('');
279+
(await this.resolveModels()).resultsModel.setValue('');
273280
}
274281
super.revert(group, options);
275282
this.setDirty(false);
@@ -287,7 +294,7 @@ export class SearchEditorInput extends EditorInput {
287294
}
288295

289296
private async suggestFileName(): Promise<URI> {
290-
const query = (await this.getModels()).configurationModel.config.query;
297+
const query = (await this.resolveModels()).configurationModel.config.query;
291298
const searchFileName = (query.replace(/[^\w \-_]+/g, '_') || 'Search') + SEARCH_EDITOR_EXT;
292299
return joinPath(await this.fileDialogService.defaultFilePath(this.pathService.defaultUriScheme), searchFileName);
293300
}

0 commit comments

Comments
 (0)