Merge pull request #2402 from zed-industries/fix-panics

Fix panic in pane.rs
This commit is contained in:
Mikayla Maki 2023-04-22 05:53:48 +12:00 committed by GitHub
commit 69273648b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 10 deletions

View file

@ -787,6 +787,10 @@ impl Pane {
) -> Option<Task<Result<()>>> {
let pane_handle = workspace.active_pane().clone();
let pane = pane_handle.read(cx);
if pane.items.is_empty() {
return None;
}
let active_item_id = pane.items[pane.active_item_index].id();
let task = Self::close_item_by_id(workspace, pane_handle, active_item_id, cx);
@ -2136,6 +2140,19 @@ mod tests {
use gpui::{executor::Deterministic, TestAppContext};
use project::FakeFs;
#[gpui::test]
async fn test_remove_active_empty(cx: &mut TestAppContext) {
Settings::test_async(cx);
let fs = FakeFs::new(cx.background());
let project = Project::test(fs, None, cx).await;
let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
workspace.update(cx, |workspace, cx| {
assert!(Pane::close_active_item(workspace, &CloseActiveItem, cx).is_none())
});
}
#[gpui::test]
async fn test_add_item_with_new_item(cx: &mut TestAppContext) {
cx.foreground().forbid_parking();