Skip to content

Untitled editors always saved on close when autosave is active #15501

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

Open
colin-grant-work opened this issue Apr 23, 2025 · 4 comments · May be fixed by #15502
Open

Untitled editors always saved on close when autosave is active #15501

colin-grant-work opened this issue Apr 23, 2025 · 4 comments · May be fixed by #15502

Comments

@colin-grant-work
Copy link
Contributor

Bug Description:

When autosave is active, untitled editors are exempted from it. When an untitled editor is closed, however, the logic to determine whether to save the widget or show a prompt to save the widget jumps straight to saving because autosave is on:

protected async closeWithSaving(widget: PostCreationSaveableWidget, options?: SaveableWidget.CloseOptions): Promise<void> {
const result = await this.shouldSaveWidget(widget, options);
if (typeof result === 'boolean') {
if (result) {
await this.save(widget, {
saveReason: SaveReason.AfterDelay
});
if (!Saveable.isDirty(widget)) {
await widget.closeWithoutSaving();
}
} else {
await widget.closeWithoutSaving();
}
}
}
protected async shouldSaveWidget(widget: PostCreationSaveableWidget, options?: SaveableWidget.CloseOptions): Promise<boolean | undefined> {
if (!Saveable.isDirty(widget)) {
return false;
}
if (this.autoSave !== 'off') {
return true;
}
const notLastWithDocument = !Saveable.closingWidgetWouldLoseSaveable(widget, Array.from(this.saveThrottles.keys()));
if (notLastWithDocument) {
await widget.closeWithoutSaving(false);
return undefined;
}
if (options && options.shouldSave) {
return options.shouldSave();
}
return new ShouldSaveDialog(widget).open();
}

Steps to Reproduce:

  1. Set the files.autoSave preference to anything but off
  2. Open an untitled editor.
  3. Write some content in the untitled editor, and then attempt to close it.
  4. A file picker dialog will open to pick the saving location.
  5. Cancel the save.
  6. The widget will still be open.
  7. Keep trying as long as your patience lasts.

Additional Information

  • Operating System: MacOS X Sequoia
  • Theia Version: 505c885
@tsmaeder tsmaeder changed the title Untitled editors unclosable without saving when autosave is active Untitled editors always saved on close when autosave is active Apr 23, 2025
@tsmaeder
Copy link
Contributor

I didn't understand the issue from the title, so I took the liberty to edit the title. Feel free revert if you disagree.

@colin-grant-work
Copy link
Contributor Author

Whatever seems more intelligible. Strictly speaking, they aren't 'always saved,' but they won't close if you don't save - your options are save and close or cancel and not close.

@tsmaeder
Copy link
Contributor

Hmh....but doesn't that kinda make sense: if you don't have a file name, where are you going to save the content? What would the correct behavior be in your opinion?

@colin-grant-work
Copy link
Contributor Author

With normal (disk-backed) files, this behavior leads to them just being saved directly, because autosave means you're happy not managing their saving. Untitled files are exempt from autosaving, and their 'save' behavior redirects to 'Save As,' which is why the file dialog pops up. To me, the correct behavior for untitled editors would be that you should get the 'Do you want to save' dialog first, and if you choose not to, the editor just closes. That is, you should be able to close without saving: you shouldn't be forced to either save or keep the editor open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants