From f54a289b6f9bade6e9cfde30bcfe46dea6e9770f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 21 Apr 2023 16:56:06 +0200 Subject: [PATCH] Remove handle to view from `TerminalElement` Co-Authored-By: Nathan Sobo --- crates/terminal_view/src/terminal_element.rs | 19 ++++--------------- crates/terminal_view/src/terminal_view.rs | 1 - 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 87c6e29f4f..496dca0e79 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -11,7 +11,7 @@ use gpui::{ serde_json::json, text_layout::{Line, RunStyle}, Drawable, Element, EventContext, FontCache, ModelContext, MouseRegion, Quad, SceneBuilder, - SizeConstraint, TextLayoutCache, ViewContext, WeakModelHandle, WeakViewHandle, + SizeConstraint, TextLayoutCache, ViewContext, WeakModelHandle, }; use itertools::Itertools; use language::CursorShape; @@ -161,20 +161,17 @@ impl LayoutRect { ///We need to keep a reference to the view for mouse events, do we need it for any other terminal stuff, or can we move that to connection? pub struct TerminalElement { terminal: WeakModelHandle, - view: WeakViewHandle, focused: bool, cursor_visible: bool, } impl TerminalElement { pub fn new( - view: WeakViewHandle, terminal: WeakModelHandle, focused: bool, cursor_visible: bool, ) -> TerminalElement { TerminalElement { - view, terminal, focused, cursor_visible, @@ -387,14 +384,13 @@ impl TerminalElement { &self, scene: &mut SceneBuilder, origin: Vector2F, - view_id: usize, visible_bounds: RectF, mode: TermMode, - _cx: &mut ViewContext, + cx: &mut ViewContext, ) { let connection = self.terminal; - let mut region = MouseRegion::new::(view_id, 0, visible_bounds); + let mut region = MouseRegion::new::(cx.view_id(), 0, visible_bounds); // Terminal Emulator controlled behavior: region = region @@ -740,14 +736,7 @@ impl Drawable for TerminalElement { let origin = bounds.origin() + vec2f(layout.size.cell_width, 0.); // Elements are ephemeral, only at paint time do we know what could be clicked by a mouse - self.attach_mouse_handlers( - scene, - origin, - self.view.id(), - visible_bounds, - layout.mode, - cx, - ); + self.attach_mouse_handlers(scene, origin, visible_bounds, layout.mode, cx); scene.push_cursor_region(gpui::CursorRegion { bounds, diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 2c549a9957..8f9e73a6f3 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -399,7 +399,6 @@ impl View for TerminalView { Stack::new() .with_child( TerminalElement::new( - cx.handle().downgrade(), terminal_handle, focused, self.should_show_cursor(focused, cx),