vim: Fix :wq in multibuffer (#24603)

Supercedes #24561
Closes #21059

Before this change we would skip saving multibuffers regardless of the
save intent. Now we correctly save them.

Along the way:
* Prompt to save when closing the last singleton copy of an item (even
if it's still open in a multibuffer).
* Update our file name prompt to pull out dirty project items from
multibuffers instead of counting multibuffers as untitled files.
* Fix our prompt test helpers to require passing the button name instead
of the index. A few tests were passing invalid responses to save
prompts.
* Refactor the code a bit to hopefully clarify it for the next bug.

Release Notes:

- Fixed edge-cases when closing multiple items including multibuffers.
Previously no prompt was generated when closing an item that was open in
a multibuffer, now you will be prompted.
- vim: Fix :wq in a multibuffer
This commit is contained in:
Conrad Irwin 2025-02-13 10:13:43 -07:00 committed by GitHub
parent 8c780ba287
commit 2f741c8686
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 318 additions and 290 deletions

View file

@ -1257,6 +1257,19 @@ pub mod test {
is_dirty: false,
})
}
pub fn new_dirty(id: u64, path: &str, cx: &mut App) -> Entity<Self> {
let entry_id = Some(ProjectEntryId::from_proto(id));
let project_path = Some(ProjectPath {
worktree_id: WorktreeId::from_usize(0),
path: Path::new(path).into(),
});
cx.new(|_| Self {
entry_id,
project_path,
is_dirty: true,
})
}
}
impl TestItem {
@ -1460,10 +1473,17 @@ pub mod test {
_: bool,
_: Entity<Project>,
_window: &mut Window,
_: &mut Context<Self>,
cx: &mut Context<Self>,
) -> Task<anyhow::Result<()>> {
self.save_count += 1;
self.is_dirty = false;
for item in &self.project_items {
item.update(cx, |item, _| {
if item.is_dirty {
item.is_dirty = false;
}
})
}
Task::ready(Ok(()))
}