refactor filestate.removeeditor
This commit is contained in:
parent
73d2ac9b45
commit
2eb3c0efbc
|
|
@ -76,20 +76,19 @@ export class OpenFile {
|
||||||
// Function to remove an editor and clean up if no more editors exist
|
// Function to remove an editor and clean up if no more editors exist
|
||||||
async removeEditor(editor: Editor, callback: () => void) {
|
async removeEditor(editor: Editor, callback: () => void) {
|
||||||
const index = this.editors.indexOf(editor);
|
const index = this.editors.indexOf(editor);
|
||||||
if (index > -1) {
|
if (index == -1) return;
|
||||||
this.editors.splice(index, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this is the last editor and the file is dirty, confirm before closing
|
// If this is the last editor and the file is dirty, confirm before closing
|
||||||
if (this.editors.length === 0 && this.isDirty()) {
|
if (this.editors.length === 1 && this.isDirty()) {
|
||||||
const confirmed = await this.confirmClose();
|
const confirmed = await this.confirmClose();
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
// Re-add the editor if user cancelled
|
|
||||||
this.editors.push(editor);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove the editor from the list
|
||||||
|
this.editors.splice(index, 1);
|
||||||
|
|
||||||
// If no more editors, remove from openFiles dictionary
|
// If no more editors, remove from openFiles dictionary
|
||||||
if (this.editors.length === 0) {
|
if (this.editors.length === 0) {
|
||||||
delete openFiles[this.filePath.val];
|
delete openFiles[this.filePath.val];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue