diff --git a/src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.ts b/src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.ts index c49856fbae2..f6f50db5041 100644 --- a/src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.ts +++ b/src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.ts @@ -178,10 +178,10 @@ export class AuxiliaryEditorPart { // will move the editors to the main window. As such, // we need to validate that we can move and otherwise // prevent the window from closing. - const canMove = editor.canMove(group.id, this.editorPartsView.mainPart.activeGroup.id); - if (typeof canMove === 'string') { + const canMoveVeto = editor.canMove(group.id, this.editorPartsView.mainPart.activeGroup.id); + if (typeof canMoveVeto === 'string') { group.openEditor(editor); - event.veto(canMove); + event.veto(canMoveVeto); break; } } diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 248fcd53609..c9e2d6a9eed 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -1335,9 +1335,10 @@ export class EditorGroupView extends Themable implements IEditorGroupView { // Validate that we can move if (!keepCopy || editor.hasCapability(EditorInputCapabilities.Singleton) /* singleton editors will always move */) { - const canMove = editor.canMove(this.id, target.id); - if (typeof canMove === 'string') { - this.dialogService.error(canMove); + const canMoveVeto = editor.canMove(this.id, target.id); + if (typeof canMoveVeto === 'string') { + this.dialogService.error(canMoveVeto, localize('moveErrorDetails', "Try saving or reverting the editor first and then try again.")); + return false; } } diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts index d5587c348d2..71d0678553f 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts @@ -438,7 +438,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput { // into another window because that means, we potentally loose the modified // state and thus trigger data loss. - return localize('editorCannotMove', "Unable to move the editor out of the window, it contains modifications that can only be saved in the this window."); + return localize('editorCannotMove', "Unable to move '{0}': editor contains changes that can only be saved in its current window.", this.getName()); } } diff --git a/src/vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService.ts b/src/vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService.ts index e9ccc023cd6..822da223eeb 100644 --- a/src/vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService.ts +++ b/src/vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService.ts @@ -49,17 +49,7 @@ export class NativeAuxiliaryWindow extends AuxiliaryWindow { protected override async handleVetoBeforeClose(e: BeforeUnloadEvent, veto: string): Promise { this.preventUnload(e); - await this.dialogService.prompt({ - type: 'error', - message: veto, - detail: localize('backupErrorDetails', "Try saving or reverting the editors with unsaved changes first and then try again."), - buttons: [ - { - label: localize({ key: 'ok', comment: ['&& denotes a mnemonic'] }, "&&OK"), - run: () => false // veto - } - ] - }); + await this.dialogService.error(veto, localize('backupErrorDetails', "Try saving or reverting the editors with unsaved changes first and then try again.")); } protected override async confirmBeforeClose(e: BeforeUnloadEvent): Promise { diff --git a/src/vs/workbench/services/editor/browser/editorResolverService.ts b/src/vs/workbench/services/editor/browser/editorResolverService.ts index f01e5972f6d..94840cb4b8f 100644 --- a/src/vs/workbench/services/editor/browser/editorResolverService.ts +++ b/src/vs/workbench/services/editor/browser/editorResolverService.ts @@ -504,9 +504,14 @@ export class EditorResolverService extends Disposable implements IEditorResolver // If the editor states it can only be opened once per resource we must close all existing ones except one and move the new one into the group const singleEditorPerResource = typeof selectedEditor.options?.singlePerResource === 'function' ? selectedEditor.options.singlePerResource() : selectedEditor.options?.singlePerResource; if (singleEditorPerResource) { - const foundInput = await this.moveExistingEditorForResource(resource, selectedEditor.editorInfo.id, group); - if (foundInput) { - return { editor: foundInput, options }; + const existingEditors = this.findExistingEditorsForResource(resource, selectedEditor.editorInfo.id); + if (existingEditors.length) { + const editor = await this.moveExistingEditorForResource(existingEditors, group); + if (editor) { + return { editor, options }; + } else { + return; // failed to move + } } } @@ -524,27 +529,21 @@ export class EditorResolverService extends Disposable implements IEditorResolver } /** - * Moves an editor with the resource and viewtype to target group if one exists + * Moves the first existing editor for a resource to the target group unless already opened there. * Additionally will close any other editors that are open for that resource and viewtype besides the first one found * @param resource The resource of the editor * @param viewType the viewtype of the editor * @param targetGroup The group to move it to - * @returns An editor input if one exists, else undefined + * @returns The moved editor input or `undefined` if the editor could not be moved */ private async moveExistingEditorForResource( - resource: URI, - viewType: string, + existingEditorsForResource: Array<{ editor: EditorInput; group: IEditorGroup }>, targetGroup: IEditorGroup, ): Promise { - const editorInfoForResource = this.findExistingEditorsForResource(resource, viewType); - if (!editorInfoForResource.length) { - return; - } - - const editorToUse = editorInfoForResource[0]; + const editorToUse = existingEditorsForResource[0]; // We should only have one editor but if there are multiple we close the others - for (const { editor, group } of editorInfoForResource) { + for (const { editor, group } of existingEditorsForResource) { if (editor !== editorToUse.editor) { const closed = await group.closeEditor(editor); if (!closed) { @@ -559,9 +558,9 @@ export class EditorResolverService extends Disposable implements IEditorResolver if (!moved) { return; } - return editorToUse.editor; } - return; + + return editorToUse.editor; } /**