Skip to content

Commit 5073c79

Browse files
committed
clean up saveBeforeShutdown function
1 parent ea22cfb commit 5073c79

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

src/vs/workbench/services/editor/browser/editorService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ export class EditorService extends Disposable implements EditorServiceImpl {
10181018
continue;
10191019
}
10201020

1021-
if (!options?.includeScratchpad && editor.hasCapability(EditorInputCapabilities.Scratchpad)) {
1021+
if ((typeof options?.includeUntitled === 'boolean' || !options?.includeUntitled?.includeScratchpad)
1022+
&& editor.hasCapability(EditorInputCapabilities.Scratchpad)) {
10221023
continue;
10231024
}
10241025

src/vs/workbench/services/editor/common/editorService.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ export interface IBaseSaveRevertAllEditorOptions {
8080
/**
8181
* Whether to include untitled editors as well.
8282
*/
83-
readonly includeUntitled?: boolean;
84-
85-
/**
86-
* Whether to include scratchpad editors.
87-
* if set to true, `includeUntitled` should also be true.
88-
*/
89-
readonly includeScratchpad?: boolean;
83+
readonly includeUntitled?: {
84+
85+
/**
86+
* Whether to include scratchpad editors.
87+
*/
88+
readonly includeScratchpad: boolean;
89+
}
90+
| boolean;
9091

9192
/**
9293
* Whether to exclude sticky editors.

src/vs/workbench/services/workingCopy/electron-sandbox/workingCopyBackupTracker.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ export class NativeWorkingCopyBackupTracker extends WorkingCopyBackupTracker imp
8989

9090
if (this.filesConfigurationService.getAutoSaveMode() !== AutoSaveMode.OFF) {
9191

92-
// Save all modified working copies
92+
// Save all modified working copies that can be auto-saved
9393
try {
94-
await this.doSaveAllBeforeShutdown(false /* not untitled */, SaveReason.AUTO);
94+
const workingCopiesToSave = modifiedWorkingCopies.filter(wc => !(wc.capabilities & WorkingCopyCapabilities.Untitled));
95+
await this.doSaveAllBeforeShutdown(workingCopiesToSave, SaveReason.AUTO);
9596
} catch (error) {
9697
this.logService.error(`[backup tracker] error saving modified working copies: ${error}`); // guard against misbehaving saves, we handle remaining modified below
9798
}
@@ -302,16 +303,8 @@ export class NativeWorkingCopyBackupTracker extends WorkingCopyBackupTracker imp
302303
return true; // veto (user canceled)
303304
}
304305

305-
private doSaveAllBeforeShutdown(modifiedWorkingCopies: IWorkingCopy[], reason: SaveReason): Promise<void>;
306-
private doSaveAllBeforeShutdown(includeAllUntitled: boolean, reason: SaveReason): Promise<void>;
307-
private doSaveAllBeforeShutdown(arg1: IWorkingCopy[] | boolean, reason: SaveReason): Promise<void> {
308-
const modifiedWorkingCopies = Array.isArray(arg1) ? arg1 : this.workingCopyService.modifiedWorkingCopies.filter(workingCopy => {
309-
if (arg1 === false && (workingCopy.capabilities & WorkingCopyCapabilities.Untitled)) {
310-
return false; // skip untitled unless explicitly included
311-
}
312-
313-
return true;
314-
});
306+
private doSaveAllBeforeShutdown(workingCopies: IWorkingCopy[], reason: SaveReason): Promise<void> {
307+
const modifiedWorkingCopies = workingCopies;
315308

316309
return this.withProgressAndCancellation(async () => {
317310

@@ -320,12 +313,10 @@ export class NativeWorkingCopyBackupTracker extends WorkingCopyBackupTracker imp
320313

321314
// First save through the editor service if we save all to benefit
322315
// from some extras like switching to untitled modified editors before saving.
323-
324316
let result: boolean | undefined = undefined;
325-
if (typeof arg1 === 'boolean' || modifiedWorkingCopies.length === this.workingCopyService.modifiedCount) {
317+
if (modifiedWorkingCopies.length === this.workingCopyService.modifiedCount) {
326318
result = (await this.editorService.saveAll({
327-
includeScratchpad: typeof arg1 === 'boolean' ? arg1 : true,
328-
includeUntitled: typeof arg1 === 'boolean' ? arg1 : true,
319+
includeUntitled: { includeScratchpad: true },
329320
...saveOptions
330321
})).success;
331322
}

0 commit comments

Comments
 (0)