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

editor: support 'close on file delete' preference #8730

Closed
vince-fugnitto opened this issue Nov 6, 2020 · 0 comments · Fixed by #8731
Closed

editor: support 'close on file delete' preference #8730

vince-fugnitto opened this issue Nov 6, 2020 · 0 comments · Fixed by #8731
Labels
editor issues related to the editor preferences issues related to preferences

Comments

@vince-fugnitto
Copy link
Member

vince-fugnitto commented Nov 6, 2020

Feature Description:

The goal is to support the close on file delete preference similarly to vscode to control the behavior when an editor's underlying resource is deleted or renamed.

image

protected async updateWidgets(event: FileChangesEvent): Promise<void> {
if (!event.gotDeleted() && !event.gotAdded()) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const pending: Promise<any>[] = [];
const dirty = new Set<string>();
const toClose = new Map<string, NavigatableWidget[]>();
for (const [uri, widget] of NavigatableWidget.get(this.shell.widgets)) {
this.updateWidget(uri, widget, event, { dirty, toClose });
}
for (const [uriString, widgets] of toClose.entries()) {
if (!dirty.has(uriString)) {
for (const widget of widgets) {
widget.close();
pending.push(waitForClosed(widget));
}
}
}
await Promise.all(pending);
}

protected updateWidget(uri: URI, widget: NavigatableWidget, event: FileChangesEvent, { dirty, toClose }: {
dirty: Set<string>;
toClose: Map<string, NavigatableWidget[]>
}): void {
const label = widget.title.label;
const deleted = label.endsWith(this.deletedSuffix);
if (event.contains(uri, FileChangeType.DELETED)) {
const uriString = uri.toString();
if (Saveable.isDirty(widget)) {
if (!deleted) {
widget.title.label += this.deletedSuffix;
}
dirty.add(uriString);
}
const widgets = toClose.get(uriString) || [];
widgets.push(widget);
toClose.set(uriString, widgets);
} else if (event.contains(uri, FileChangeType.ADDED)) {
if (deleted) {
widget.title.label = widget.title.label.substr(0, label.length - this.deletedSuffix.length);
}
}
}

Steps to Reproduce:

  1. start the application and open a file (ex: readme.md).
  2. delete the file on the filesystem.
  3. the application currently closes the editor.
@vince-fugnitto vince-fugnitto added bug bugs found in the application editor issues related to the editor critical critical bugs / problems and removed critical critical bugs / problems labels Nov 6, 2020
@vince-fugnitto vince-fugnitto changed the title editor: widget closes when files are deleted from filesystem editor: support 'close on file delete' preference Nov 6, 2020
@vince-fugnitto vince-fugnitto added preferences issues related to preferences and removed bug bugs found in the application labels Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor issues related to the editor preferences issues related to preferences
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant