refactor filestate.removeeditor

This commit is contained in:
Quinten Kock 2025-11-13 01:46:15 +01:00
parent 73d2ac9b45
commit 2eb3c0efbc
1 changed files with 5 additions and 6 deletions

View File

@ -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];