From 2eb3c0efbc82d3111619789ea8a0f8d089cf2675 Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Thu, 13 Nov 2025 01:46:15 +0100 Subject: [PATCH] refactor filestate.removeeditor --- src/app/filestate.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/app/filestate.ts b/src/app/filestate.ts index a8fc936..8be28ef 100644 --- a/src/app/filestate.ts +++ b/src/app/filestate.ts @@ -76,20 +76,19 @@ export class OpenFile { // Function to remove an editor and clean up if no more editors exist async removeEditor(editor: Editor, callback: () => void) { const index = this.editors.indexOf(editor); - if (index > -1) { - this.editors.splice(index, 1); - } + if (index == -1) return; // 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(); if (!confirmed) { - // Re-add the editor if user cancelled - this.editors.push(editor); return; } } + // Remove the editor from the list + this.editors.splice(index, 1); + // If no more editors, remove from openFiles dictionary if (this.editors.length === 0) { delete openFiles[this.filePath.val];