Refactor item-closing actions (#31838)
While working on - https://github.com/zed-industries/zed/pull/31783 - https://github.com/zed-industries/zed/pull/31786 ... I noticed some areas that could be improved through refactoring. The bug in https://github.com/zed-industries/zed/pull/31783 came from having duplicate code. The fix had been applied to one version, but not the duplicated code. This PR attempts to do some initial clean up, through some refactoring. Release Notes: - N/A
This commit is contained in:
parent
cc536655a1
commit
24e4446cd3
4 changed files with 184 additions and 178 deletions
|
@ -2658,7 +2658,7 @@ impl Workspace {
|
|||
let mut tasks = Vec::new();
|
||||
|
||||
if retain_active_pane {
|
||||
if let Some(current_pane_close) = current_pane.update(cx, |pane, cx| {
|
||||
let current_pane_close = current_pane.update(cx, |pane, cx| {
|
||||
pane.close_inactive_items(
|
||||
&CloseInactiveItems {
|
||||
save_intent: None,
|
||||
|
@ -2667,9 +2667,9 @@ impl Workspace {
|
|||
window,
|
||||
cx,
|
||||
)
|
||||
}) {
|
||||
tasks.push(current_pane_close);
|
||||
};
|
||||
});
|
||||
|
||||
tasks.push(current_pane_close);
|
||||
}
|
||||
|
||||
for pane in self.panes() {
|
||||
|
@ -2677,7 +2677,7 @@ impl Workspace {
|
|||
continue;
|
||||
}
|
||||
|
||||
if let Some(close_pane_items) = pane.update(cx, |pane: &mut Pane, cx| {
|
||||
let close_pane_items = pane.update(cx, |pane: &mut Pane, cx| {
|
||||
pane.close_all_items(
|
||||
&CloseAllItems {
|
||||
save_intent: Some(save_intent),
|
||||
|
@ -2686,9 +2686,9 @@ impl Workspace {
|
|||
window,
|
||||
cx,
|
||||
)
|
||||
}) {
|
||||
tasks.push(close_pane_items)
|
||||
}
|
||||
});
|
||||
|
||||
tasks.push(close_pane_items)
|
||||
}
|
||||
|
||||
if tasks.is_empty() {
|
||||
|
@ -8082,7 +8082,7 @@ mod tests {
|
|||
assert!(!msg.contains("4.txt"));
|
||||
|
||||
cx.simulate_prompt_answer("Cancel");
|
||||
close.await.unwrap();
|
||||
close.await;
|
||||
|
||||
left_pane
|
||||
.update_in(cx, |left_pane, window, cx| {
|
||||
|
@ -8114,7 +8114,7 @@ mod tests {
|
|||
cx.simulate_prompt_answer("Save all");
|
||||
|
||||
cx.executor().run_until_parked();
|
||||
close.await.unwrap();
|
||||
close.await;
|
||||
right_pane.read_with(cx, |pane, _| {
|
||||
assert_eq!(pane.items_len(), 0);
|
||||
});
|
||||
|
@ -9040,18 +9040,16 @@ mod tests {
|
|||
"Should select the multi buffer in the pane"
|
||||
);
|
||||
});
|
||||
let close_all_but_multi_buffer_task = pane
|
||||
.update_in(cx, |pane, window, cx| {
|
||||
pane.close_inactive_items(
|
||||
&CloseInactiveItems {
|
||||
save_intent: Some(SaveIntent::Save),
|
||||
close_pinned: true,
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.expect("should have inactive files to close");
|
||||
let close_all_but_multi_buffer_task = pane.update_in(cx, |pane, window, cx| {
|
||||
pane.close_inactive_items(
|
||||
&CloseInactiveItems {
|
||||
save_intent: Some(SaveIntent::Save),
|
||||
close_pinned: true,
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
cx.background_executor.run_until_parked();
|
||||
assert!(!cx.has_pending_prompt());
|
||||
close_all_but_multi_buffer_task
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue