Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto save - skip non-dirty editors #200468

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/vs/workbench/browser/parts/editor/editorAutoSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution

private maybeTriggerAutoSave(reason: SaveReason, editorIdentifier?: IEditorIdentifier): void {
if (editorIdentifier) {
if (editorIdentifier.editor.isReadonly() || editorIdentifier.editor.hasCapability(EditorInputCapabilities.Untitled)) {
if (
!editorIdentifier.editor.isDirty() ||
editorIdentifier.editor.isReadonly() ||
editorIdentifier.editor.hasCapability(EditorInputCapabilities.Untitled)
) {
return; // no auto save for readonly or untitled editors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add non-dirty to this comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

}

Expand Down Expand Up @@ -170,15 +174,15 @@ export class EditorAutoSave extends Disposable implements IWorkbenchContribution
}

private scheduleAutoSave(workingCopy: IWorkingCopy): void {
if (workingCopy.capabilities & WorkingCopyCapabilities.Untitled) {
return; // we never auto save untitled working copies
}

const autoSaveAfterDelay = this.filesConfigurationService.getAutoSaveConfiguration(workingCopy.resource).autoSaveDelay;
if (typeof autoSaveAfterDelay !== 'number') {
return; // auto save after delay must be enabled
}

if (workingCopy.capabilities & WorkingCopyCapabilities.Untitled) {
return; // we never auto save untitled working copies
}

// Clear any running auto save operation
this.discardAutoSave(workingCopy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ export abstract class WorkingCopyBackupTracker extends Disposable {
return workingCopy.backupDelay; // respect working copy override
}

let autoSaveMode = this.filesConfigurationService.getAutoSaveMode(workingCopy.resource);
let autoSaveMode: AutoSaveMode;
if (workingCopy.capabilities & WorkingCopyCapabilities.Untitled) {
autoSaveMode = AutoSaveMode.OFF; // auto-save is never on for untitled working copies
} else {
autoSaveMode = this.filesConfigurationService.getAutoSaveMode(workingCopy.resource);
}

return WorkingCopyBackupTracker.DEFAULT_BACKUP_SCHEDULE_DELAYS[autoSaveMode];
Expand Down