提交 781950c2 编写于 作者: B Benjamin Pasero

editors - change whenClosed to use editor interface

上级 705e1ba5
......@@ -635,7 +635,7 @@ export class NativeWindow extends Disposable {
private async trackClosedWaitFiles(waitMarkerFile: URI, resourcesToWaitFor: URI[]): Promise<void> {
// Wait for the resources to be closed in the editor...
await this.editorService.whenClosed(resourcesToWaitFor, { waitForSaved: true });
await this.editorService.whenClosed(resourcesToWaitFor.map(resource => ({ resource })), { waitForSaved: true });
// ...before deleting the wait marker file
await this.fileService.del(waitMarkerFile);
......
......@@ -1164,8 +1164,8 @@ export class EditorService extends Disposable implements EditorServiceImpl {
//#region Editor Tracking
whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise<void> {
let remainingResources = [...resources];
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise<void> {
let remainingEditors = [...editors];
return new Promise(resolve => {
const listener = this.onDidCloseEditor(async event => {
......@@ -1174,8 +1174,8 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Remove from resources to wait for being closed based on the
// resources from editors that got closed
remainingResources = remainingResources.filter(resource => {
if (isEqual(resource, masterResource) || isEqual(resource, detailsResource)) {
remainingEditors = remainingEditors.filter(({ resource }) => {
if (this.uriIdentitiyService.extUri.isEqual(resource, masterResource) || this.uriIdentitiyService.extUri.isEqual(resource, detailsResource)) {
return false; // remove - the closing editor matches this resource
}
......@@ -1183,15 +1183,15 @@ export class EditorService extends Disposable implements EditorServiceImpl {
});
// All resources to wait for being closed are closed
if (remainingResources.length === 0) {
if (remainingEditors.length === 0) {
if (options?.waitForSaved) {
// If auto save is configured with the default delay (1s) it is possible
// to close the editor while the save still continues in the background. As such
// we have to also check if the files to track for are dirty and if so wait
// we have to also check if the editors to track for are dirty and if so wait
// for them to get saved.
const dirtyFiles = resources.filter(resource => this.workingCopyService.isDirty(resource));
if (dirtyFiles.length > 0) {
await Promise.all(dirtyFiles.map(async dirtyFile => await this.whenSaved(dirtyFile)));
const dirtyResources = editors.filter(({ resource }) => this.workingCopyService.isDirty(resource)).map(({ resource }) => resource);
if (dirtyResources.length > 0) {
await Promise.all(dirtyResources.map(async resource => await this.whenSaved(resource)));
}
}
......@@ -1211,7 +1211,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Otherwise resolve promise when resource is saved
const listener = this.workingCopyService.onDidChangeDirty(workingCopy => {
if (!workingCopy.isDirty() && isEqual(resource, workingCopy.resource)) {
if (!workingCopy.isDirty() && this.uriIdentitiyService.extUri.isEqual(resource, workingCopy.resource)) {
listener.dispose();
resolve();
......@@ -1340,7 +1340,7 @@ export class DelegatingEditorService implements IEditorService {
registerCustomEditorViewTypesHandler(source: string, handler: ICustomEditorViewTypesHandler): IDisposable { return this.editorService.registerCustomEditorViewTypesHandler(source, handler); }
whenClosed(resources: URI[]): Promise<void> { return this.editorService.whenClosed(resources); }
whenClosed(editors: IResourceEditorInput[]): Promise<void> { return this.editorService.whenClosed(editors); }
//#endregion
}
......
......@@ -289,12 +289,11 @@ export interface IEditorService {
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean>;
/**
* Track the provided list of resources for being opened as editors
* and resolve once all have been closed.
* Track the provided editors until all have been closed.
*
* @param options use `waitForSaved: true` to wait for the resources
* being saved. If auto-save is enabled, it may be possible to close
* an editor while the save continues in the background.
*/
whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise<void>;
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise<void>;
}
......@@ -1084,7 +1084,7 @@ suite('EditorService', () => {
const editor = await service.openEditor(input1, { pinned: true });
await service.openEditor(input2, { pinned: true });
const whenClosed = service.whenClosed([input1.resource, input2.resource]);
const whenClosed = service.whenClosed([input1, input2]);
editor?.group?.closeAllEditors();
......
......@@ -224,7 +224,7 @@ export class BrowserHostService extends Disposable implements IHostService {
(async () => {
// Wait for the resources to be closed in the editor...
await this.editorService.whenClosed(fileOpenables.map(openable => openable.fileUri), { waitForSaved: true });
await this.editorService.whenClosed(fileOpenables.map(openable => ({ resource: openable.fileUri })), { waitForSaved: true });
// ...before deleting the wait marker file
await this.fileService.del(waitMarkerFileURI);
......
......@@ -676,7 +676,7 @@ export class TestEditorService implements EditorServiceImpl {
saveAll(options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise<void> { throw new Error('Method not implemented.'); }
whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise<void> { throw new Error('Method not implemented.'); }
}
export class TestFileService implements IFileService {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册