From 9c8b6f4a9f9f2ed3096998ed21da40383ecb78df Mon Sep 17 00:00:00 2001 From: CharlesChen0823 Date: Fri, 30 Aug 2024 21:12:42 +0800 Subject: [PATCH] workspace: Fix weird behavior when save replaces the existing open file (#17123) Fixes this weird behavior: - open an file, like `test.rs` - `ctrl-n` create an new buffer - `ctrl-s` save new buffer with name `test.rs`, select replace old file. - the older open file also exist, this is weird. Release Notes: - Fixed two panes staying opening when saving a new buffer with the same filename as a file that was already open. --- crates/workspace/src/pane.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 84c404c9f6564dc40806b20f13d0c4aafc6b0fa5..e8ac67b0e05c49d880daf9e6913ae272995cd8f7 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1556,8 +1556,16 @@ impl Pane { .update(cx, |workspace, cx| workspace.prompt_for_new_path(cx)) })??; if let Some(abs_path) = abs_path.await.ok().flatten() { - pane.update(cx, |_, cx| item.save_as(project, abs_path, cx))? - .await?; + pane.update(cx, |pane, cx| { + if let Some(item) = pane.item_for_path(abs_path.clone(), cx) { + if let Some(idx) = pane.index_for_item(&*item) { + pane.remove_item(idx, false, false, cx); + } + } + + item.save_as(project, abs_path, cx) + })? + .await?; } else { return Ok(false); }