From b8539373aa18f704d4eb3d3c4ac706036d6fa3d4 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 5 Jan 2024 15:54:23 +0100 Subject: [PATCH] Avoid leaking `TerminalPanel`, which would in turn leak `Project` --- crates/terminal_view/src/terminal_panel.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index 82d7208ef8..32bad620ba 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -53,7 +53,7 @@ pub struct TerminalPanel { impl TerminalPanel { fn new(workspace: &Workspace, cx: &mut ViewContext) -> Self { - let terminal_panel = cx.view().clone(); + let terminal_panel = cx.view().downgrade(); let pane = cx.new_view(|cx| { let mut pane = Pane::new( workspace.weak_handle(), @@ -77,14 +77,17 @@ impl TerminalPanel { pane.set_can_navigate(false, cx); pane.display_nav_history_buttons(false); pane.set_render_tab_bar_buttons(cx, move |pane, cx| { + let terminal_panel = terminal_panel.clone(); h_stack() .gap_2() .child( IconButton::new("plus", Icon::Plus) .icon_size(IconSize::Small) - .on_click(cx.listener_for(&terminal_panel, |terminal_panel, _, cx| { - terminal_panel.add_terminal(None, cx); - })) + .on_click(move |_, cx| { + terminal_panel + .update(cx, |panel, cx| panel.add_terminal(None, cx)) + .log_err(); + }) .tooltip(|cx| Tooltip::text("New Terminal", cx)), ) .child({