mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-30 12:15:32 +01:00
editor - guard against throwing close handlers (#246092)
This commit is contained in:
@@ -586,9 +586,17 @@ abstract class AbstractCloseAllAction extends Action2 {
|
||||
|
||||
for (const { editor, groupId } of editorService.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: this.excludeSticky })) {
|
||||
let confirmClose = false;
|
||||
let handlerDidError = false;
|
||||
if (editor.closeHandler) {
|
||||
confirmClose = editor.closeHandler.showConfirm(); // custom handling of confirmation on close
|
||||
} else {
|
||||
try {
|
||||
confirmClose = editor.closeHandler.showConfirm(); // custom handling of confirmation on close
|
||||
} catch (error) {
|
||||
logService.error(error);
|
||||
handlerDidError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!editor.closeHandler || handlerDidError) {
|
||||
confirmClose = editor.isDirty() && !editor.isSaving(); // default confirm only when dirty and not saving
|
||||
}
|
||||
|
||||
|
||||
@@ -1771,12 +1771,18 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
await this.hostService.focus(getWindow(this.element));
|
||||
|
||||
// Let editor handle confirmation if implemented
|
||||
let handlerDidError = false;
|
||||
if (typeof editor.closeHandler?.confirm === 'function') {
|
||||
confirmation = await editor.closeHandler.confirm([{ editor, groupId: this.id }]);
|
||||
try {
|
||||
confirmation = await editor.closeHandler.confirm([{ editor, groupId: this.id }]);
|
||||
} catch (e) {
|
||||
this.logService.error(e);
|
||||
handlerDidError = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Show a file specific confirmation
|
||||
else {
|
||||
// Show a file specific confirmation if there is no handler or it errored
|
||||
if (typeof editor.closeHandler?.confirm !== 'function' || handlerDidError) {
|
||||
let name: string;
|
||||
if (editor instanceof SideBySideEditorInput) {
|
||||
name = editor.primary.getName(); // prefer shorter names by using primary's name in this case
|
||||
@@ -1839,7 +1845,11 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
|
||||
private shouldConfirmClose(editor: EditorInput): boolean {
|
||||
if (editor.closeHandler) {
|
||||
return editor.closeHandler.showConfirm(); // custom handling of confirmation on close
|
||||
try {
|
||||
return editor.closeHandler.showConfirm(); // custom handling of confirmation on close
|
||||
} catch (error) {
|
||||
this.logService.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
return editor.isDirty() && !editor.isSaving(); // editor must be dirty and not saving
|
||||
|
||||
Reference in New Issue
Block a user