From e268ea8463e2c9c86468756ee1c42d9b16d2c18f Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Tue, 18 Jul 2023 19:05:35 -0700
Subject: fix "can't edit twice" bug

---
 extension/src/diffs.ts | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

(limited to 'extension')

diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts
index 1e63c5f6..1130a06a 100644
--- a/extension/src/diffs.ts
+++ b/extension/src/diffs.ts
@@ -38,6 +38,15 @@ class DiffManager {
 
   constructor() {
     this.setupDirectory();
+
+    // Listen for file closes, and if it's a diff file, clean up
+    vscode.workspace.onDidCloseTextDocument((document) => {
+      const newFilepath = document.uri.fsPath;
+      const diffInfo = this.diffs.get(newFilepath);
+      if (diffInfo) {
+        this.cleanUpDiff(diffInfo, false);
+      }
+    });
   }
 
   private escapeFilepath(filepath: string): string {
@@ -160,9 +169,9 @@ class DiffManager {
     return newFilepath;
   }
 
-  cleanUpDiff(diffInfo: DiffInfo) {
+  cleanUpDiff(diffInfo: DiffInfo, hideEditor: boolean = true) {
     // Close the editor, remove the record, delete the file
-    if (diffInfo.editor) {
+    if (hideEditor && diffInfo.editor) {
       vscode.window.showTextDocument(diffInfo.editor.document);
       vscode.commands.executeCommand("workbench.action.closeActiveEditor");
     }
-- 
cgit v1.2.3-70-g09d2