From 21650c5c4fa23ade0a5d31740fe6b41ec1e0caae Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 18 Nov 2026 21:53:22 +0200 Subject: [PATCH] sidebar: Fix a panic when a project menu entry is confirmed with Enter `ContextMenu::confirm` runs an entry's handler while the menu is being updated. The worktree, "Move Up", "Move Down" and "Remove" entries of the project header menu emitted `DismissEvent` on that menu inside the handler, which updated it a second time. A mouse click runs the handler outside of the menu's update, so only the keyboard was affected. Dismiss the menu in a deferred call instead. --- crates/sidebar/src/sidebar.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index da0dc357306..efa17b54903 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -715,6 +715,13 @@ fn workspace_menu_worktree_labels( .collect() } +fn defer_menu_dismissal(menu: &WeakEntity, window: &mut Window, cx: &mut App) { + let menu = menu.clone(); + window.defer(cx, move |_, cx| { + menu.update(cx, |_, cx| cx.emit(DismissEvent)).ok(); + }); +} + fn apply_worktree_label_mode( mut worktrees: Vec, mode: AgentThreadWorktreeLabel, @@ -3147,9 +3154,7 @@ impl Sidebar { ); }) .ok(); - activate_weak_menu - .update(cx, |_, cx| cx.emit(DismissEvent)) - .ok(); + defer_menu_dismissal(&activate_weak_menu, window, cx); }, ); } @@ -3170,30 +3175,26 @@ impl Sidebar { ContextMenuEntry::new("Move Up") .action(Box::new(MoveProjectUp)) .disabled(!can_move_up) - .handler(move |_window, cx| { + .handler(move |window, cx| { move_up_multi_workspace .update(cx, |mw, cx| { mw.move_project_group_up(&move_up_key, cx); }) .ok(); - move_up_weak_menu - .update(cx, |_, cx| cx.emit(DismissEvent)) - .ok(); + defer_menu_dismissal(&move_up_weak_menu, window, cx); }), ) .item( ContextMenuEntry::new("Move Down") .action(Box::new(MoveProjectDown)) .disabled(!can_move_down) - .handler(move |_window, cx| { + .handler(move |window, cx| { move_down_multi_workspace .update(cx, |mw, cx| { mw.move_project_group_down(&move_down_key, cx); }) .ok(); - move_down_weak_menu - .update(cx, |_, cx| cx.emit(DismissEvent)) - .ok(); + defer_menu_dismissal(&move_down_weak_menu, window, cx); }), ) }); @@ -3208,7 +3209,7 @@ impl Sidebar { .detach_and_log_err(cx); }) .ok(); - weak_menu.update(cx, |_, cx| cx.emit(DismissEvent)).ok(); + defer_menu_dismissal(&weak_menu, window, cx); }) });