From 0a50d7e780cb9c055820e15e76aae378c6201202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Thu, 7 Jul 2022 17:02:54 +0200 Subject: [PATCH] Close diff only for file in index or working state (#1140) Fixes #1137 --- src/commandsAndMenu.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index bddbc9986..f55da4088 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -607,14 +607,23 @@ export function addCommands( modelIsLoading.reject(msg); } - gitModel.statusChanged.connect((_, status) => { - const targetFile = status.files.find( - fileStatus => model.filename === fileStatus.from - ); - if (!targetFile || targetFile.status === 'unmodified') { - mainAreaItem.dispose(); - } - }); + if ( + model.challenger.source === Git.Diff.SpecialRef.INDEX || + model.challenger.source === Git.Diff.SpecialRef.WORKING || + model.reference.source === Git.Diff.SpecialRef.INDEX || + model.reference.source === Git.Diff.SpecialRef.WORKING + ) { + const maybeClose = (_: IGitExtension, status: Git.IStatus) => { + const targetFile = status.files.find( + fileStatus => model.filename === fileStatus.from + ); + if (!targetFile || targetFile.status === 'unmodified') { + gitModel.statusChanged.disconnect(maybeClose); + mainAreaItem.dispose(); + } + }; + gitModel.statusChanged.connect(maybeClose); + } } return mainAreaItem;