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.
This commit is contained in:
CharlesChen0823 2024-08-30 21:12:42 +08:00 committed by GitHub
parent 7cc24eaf4b
commit 9c8b6f4a9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1556,7 +1556,15 @@ 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))?
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);