Skip to content

Commit 5e09466

Browse files
author
Benjamin Pasero
committed
editors - stop support for EditorGroup.isOpen({ resource })
1 parent bcdc8ca commit 5e09466

18 files changed

Lines changed: 67 additions & 109 deletions

File tree

src/vs/workbench/browser/dnd.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ export class ResourcesDropHandler {
243243
droppedDirtyEditor.resource = this.textFileService.untitled.create({ mode: droppedDirtyEditor.mode, encoding: droppedDirtyEditor.encoding }).getResource();
244244
}
245245

246-
// Return early if the resource is already dirty in target or opened already
247-
if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen({ resource: droppedDirtyEditor.resource })) {
246+
// Return early if the resource is already dirty in target or opened already as file
247+
if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen(this.editorService.createInput({ resource: droppedDirtyEditor.resource, forceFile: true }))) {
248248
return false;
249249
}
250250

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { hash } from 'vs/base/common/hash';
4949
import { guessMimeTypes } from 'vs/base/common/mime';
5050
import { extname } from 'vs/base/common/resources';
5151
import { Schemas } from 'vs/base/common/network';
52-
import { EditorActivation, EditorOpenContext, IResourceInput } from 'vs/platform/editor/common/editor';
52+
import { EditorActivation, EditorOpenContext } from 'vs/platform/editor/common/editor';
5353
import { IDialogService, IFileDialogService, ConfirmResult } from 'vs/platform/dialogs/common/dialogs';
5454
import { ILogService } from 'vs/platform/log/common/log';
5555

@@ -766,7 +766,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
766766
return this._group.indexOf(editor);
767767
}
768768

769-
isOpened(editor: EditorInput | IResourceInput): boolean {
769+
isOpened(editor: EditorInput): boolean {
770770
return this._group.contains(editor);
771771
}
772772

src/vs/workbench/common/editor/editorGroup.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/co
1010
import { dispose, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
1111
import { Registry } from 'vs/platform/registry/common/platform';
1212
import { coalesce } from 'vs/base/common/arrays';
13-
import { isEqual } from 'vs/base/common/resources';
14-
import { IResourceInput } from 'vs/platform/editor/common/editor';
1513

1614
const EditorOpenPositioning = {
1715
LEFT: 'left',
@@ -573,7 +571,7 @@ export class EditorGroup extends Disposable {
573571
return this.editors[index];
574572
}
575573

576-
contains(candidate: EditorInput | IResourceInput, searchInSideBySideEditors?: boolean): boolean {
574+
contains(candidate: EditorInput, searchInSideBySideEditors?: boolean): boolean {
577575
for (const editor of this.editors) {
578576
if (this.matches(editor, candidate)) {
579577
return true;
@@ -589,18 +587,12 @@ export class EditorGroup extends Disposable {
589587
return false;
590588
}
591589

592-
private matches(editor: IEditorInput | null, candidate: IEditorInput | IResourceInput | null): boolean {
590+
private matches(editor: IEditorInput | null, candidate: IEditorInput | null): boolean {
593591
if (!editor || !candidate) {
594592
return false;
595593
}
596594

597-
if (candidate instanceof EditorInput) {
598-
return editor.matches(candidate);
599-
}
600-
601-
const resource = editor.getResource();
602-
603-
return !!(resource && isEqual(resource, (candidate as IResourceInput).resource));
595+
return editor.matches(candidate);
604596
}
605597

606598
clone(): EditorGroup {

src/vs/workbench/contrib/backup/common/backupRestorer.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1010
import { IResourceInput } from 'vs/platform/editor/common/editor';
1111
import { Schemas } from 'vs/base/common/network';
1212
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
13-
import { IUntitledTextResourceInput } from 'vs/workbench/common/editor';
14-
import { toLocalResource } from 'vs/base/common/resources';
13+
import { IUntitledTextResourceInput, IEditorInput } from 'vs/workbench/common/editor';
14+
import { toLocalResource, isEqual } from 'vs/base/common/resources';
1515
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1616

1717
export class BackupRestorer implements IWorkbenchContribution {
@@ -51,7 +51,7 @@ export class BackupRestorer implements IWorkbenchContribution {
5151
const unresolvedBackups: URI[] = [];
5252

5353
await Promise.all(backups.map(async backup => {
54-
const openedEditor = this.editorService.getOpened({ resource: backup });
54+
const openedEditor = this.findEditorByResource(backup);
5555
if (openedEditor) {
5656
try {
5757
await openedEditor.resolve(); // trigger load
@@ -66,6 +66,16 @@ export class BackupRestorer implements IWorkbenchContribution {
6666
return unresolvedBackups;
6767
}
6868

69+
private findEditorByResource(resource: URI): IEditorInput | undefined {
70+
for (const editor of this.editorService.editors) {
71+
if (isEqual(editor.getResource(), resource)) {
72+
return editor;
73+
}
74+
}
75+
76+
return undefined;
77+
}
78+
6979
private async doOpenEditors(resources: URI[]): Promise<void> {
7080
const hasOpenedEditors = this.editorService.visibleEditors.length > 0;
7181
const inputs = resources.map((resource, index) => this.resolveInput(resource, index, hasOpenedEditors));

src/vs/workbench/contrib/files/browser/editors/fileEditorTracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
288288
return false; // resource must not be pending to save
289289
}
290290

291-
if (this.editorService.isOpen({ resource })) {
292-
return false; // model must not be opened already
291+
if (this.editorService.isOpen(this.editorService.createInput({ resource, forceFile: true }))) {
292+
return false; // model must not be opened already as file
293293
}
294294

295295
return true;

src/vs/workbench/contrib/files/test/browser/fileEditorTracker.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ suite('Files - FileEditorTracker', () => {
106106

107107
const resource = toResource.call(this, '/path/index.txt');
108108

109-
assert.ok(!accessor.editorService.isOpen({ resource }));
109+
assert.ok(!accessor.editorService.isOpen(accessor.editorService.createInput({ resource, forceFile: true })));
110110

111111
const model = await accessor.textFileService.files.resolve(resource) as IResolvedTextFileEditorModel;
112112

113113
model.textEditorModel.setValue('Super Good');
114114

115115
await awaitEditorOpening(accessor.editorService);
116-
assert.ok(accessor.editorService.isOpen({ resource }));
116+
assert.ok(accessor.editorService.isOpen(accessor.editorService.createInput({ resource, forceFile: true })));
117117

118118
part.dispose();
119119
tracker.dispose();

src/vs/workbench/contrib/search/browser/searchActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { ITreeNavigator } from 'vs/base/browser/ui/tree/tree';
3232
import { createEditorFromSearchResult, openNewSearchEditor, SearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorCommands';
3333

3434
import type { SearchEditor } from 'vs/workbench/contrib/search/browser/searchEditor';
35+
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
3536

3637
export function isSearchViewFocused(viewletService: IViewletService, panelService: IPanelService): boolean {
3738
const searchView = getSearchView(viewletService, panelService);
@@ -586,6 +587,7 @@ export class OpenResultsInEditorAction extends Action {
586587
@IEditorService private editorService: IEditorService,
587588
@IConfigurationService private configurationService: IConfigurationService,
588589
@IInstantiationService private readonly instantiationService: IInstantiationService,
590+
@ITextFileService private readonly textFileService: ITextFileService
589591
) {
590592
super(id, label, 'codicon-go-to-file');
591593
}
@@ -602,7 +604,7 @@ export class OpenResultsInEditorAction extends Action {
602604
async run() {
603605
const searchView = getSearchView(this.viewletService, this.panelService);
604606
if (searchView && this.configurationService.getValue<ISearchConfigurationProperties>('search').enableSearchEditorPreview) {
605-
await createEditorFromSearchResult(searchView.searchResult, searchView.searchIncludePattern.getValue(), searchView.searchExcludePattern.getValue(), this.labelService, this.editorService, this.instantiationService);
607+
await createEditorFromSearchResult(searchView.searchResult, searchView.searchIncludePattern.getValue(), searchView.searchExcludePattern.getValue(), this.labelService, this.editorService, this.textFileService, this.instantiationService);
606608
}
607609
}
608610
}

src/vs/workbench/contrib/search/browser/searchEditorCommands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export const openNewSearchEditor =
480480
};
481481

482482
export const createEditorFromSearchResult =
483-
async (searchResult: SearchResult, rawIncludePattern: string, rawExcludePattern: string, labelService: ILabelService, editorService: IEditorService, instantiationService: IInstantiationService) => {
483+
async (searchResult: SearchResult, rawIncludePattern: string, rawExcludePattern: string, labelService: ILabelService, editorService: IEditorService, textFileService: ITextFileService, instantiationService: IInstantiationService) => {
484484
if (!searchResult.query) {
485485
console.error('Expected searchResult.query to be defined. Got', searchResult);
486486
return;
@@ -500,7 +500,7 @@ export const createEditorFromSearchResult =
500500

501501
let id = 0;
502502

503-
let existing = editorService.getOpened(possible);
503+
let existing = textFileService.untitled.get(possible.resource);
504504
while (existing) {
505505
if (existing instanceof UntitledTextEditorInput) {
506506
const model = await existing.resolve();
@@ -510,7 +510,7 @@ export const createEditorFromSearchResult =
510510
}
511511
}
512512
possible.resource = possible.resource.with({ path: searchTerm + '-' + ++id });
513-
existing = editorService.getOpened(possible);
513+
existing = textFileService.untitled.get(possible.resource);
514514
}
515515

516516
const input = instantiationService.createInstance(

src/vs/workbench/contrib/search/browser/searchView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ export class SearchView extends ViewPane {
15591559

15601560
this.messageDisposables.push(dom.addDisposableListener(openInEditorLink, dom.EventType.CLICK, (e: MouseEvent) => {
15611561
dom.EventHelper.stop(e, false);
1562-
createEditorFromSearchResult(this.searchResult, this.searchIncludePattern.getValue(), this.searchExcludePattern.getValue(), this.labelService, this.editorService, this.instantiationService);
1562+
createEditorFromSearchResult(this.searchResult, this.searchIncludePattern.getValue(), this.searchExcludePattern.getValue(), this.labelService, this.editorService, this.textFileService, this.instantiationService);
15631563
}));
15641564

15651565
} else {

src/vs/workbench/electron-browser/window.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,18 +608,16 @@ export class ElectronWindow extends Disposable {
608608
}
609609

610610
private trackClosedWaitFiles(waitMarkerFile: URI, resourcesToWaitFor: URI[]): IDisposable {
611+
// In wait mode, listen to changes to the editors and wait until the files
612+
// are closed that the user wants to wait for. When this happens we delete
613+
// the wait marker file to signal to the outside that editing is done.
611614
const listener = this.editorService.onDidCloseEditor(async event => {
612615
const closedResource = toResource(event.editor, { supportSideBySide: SideBySideEditor.MASTER });
613616

614-
// In wait mode, listen to changes to the editors and wait until the files
615-
// are closed that the user wants to wait for. When this happens we delete
616-
// the wait marker file to signal to the outside that editing is done.
617-
if (
618-
// for https://github.com/microsoft/vscode/issues/75861
619-
(resourcesToWaitFor.length === 1 && isEqual(closedResource, resourcesToWaitFor[0])) ||
620-
// any other case we simply check for all resources to wait for
621-
resourcesToWaitFor.every(resource => !this.editorService.isOpen({ resource }))
622-
) {
617+
// Remove from resources to wait for
618+
resourcesToWaitFor = resourcesToWaitFor.filter(resourceToWaitFor => !isEqual(closedResource, resourceToWaitFor));
619+
620+
if (resourcesToWaitFor.length === 0) {
623621
// If auto save is configured with the default delay (1s) it is possible
624622
// to close the editor while the save still continues in the background. As such
625623
// we have to also check if the files to wait for are dirty and if so wait

0 commit comments

Comments
 (0)