From 86865431b98b0cc62aef5b35185228b5953be0e1 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 8 Nov 2023 17:01:50 -0800 Subject: [PATCH] Assign gutter widht on editor view when painting element --- crates/editor2/src/editor.rs | 8 ++++---- crates/editor2/src/element.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 618157fb96379abffa3c9dd8ad1c3b5a5cb5b44d..8cc58a87bff325a7544de8236cd0d7f3464a9680 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -674,6 +674,7 @@ pub struct Editor { next_inlay_id: usize, _subscriptions: Vec, pixel_position_of_newest_cursor: Option>, + gutter_width: Pixels, style: Option, } @@ -1984,6 +1985,7 @@ impl Editor { inlay_hint_cache: InlayHintCache::new(inlay_hint_settings), gutter_hovered: false, pixel_position_of_newest_cursor: None, + gutter_width: Default::default(), style: None, _subscriptions: vec![ cx.observe(&buffer, Self::on_buffer_changed), @@ -9771,14 +9773,12 @@ impl InputHandler for Editor { let scroll_position = snapshot.scroll_position(); let scroll_left = scroll_position.x * em_width; - // todo!() How do we actually get the gutter margin here? - let gutter_margin = px(84.46154); - let start = OffsetUtf16(range_utf16.start).to_display_point(&snapshot); let end = OffsetUtf16(range_utf16.end).to_display_point(&snapshot); let start_y = line_height * (start.row() as f32 - scroll_position.y); let end_y = line_height * (end.row() as f32 - scroll_position.y); - let start_x = snapshot.x_for_point(start, &text_layout_details) - scroll_left + gutter_margin; + let start_x = + snapshot.x_for_point(start, &text_layout_details) - scroll_left + self.gutter_width; let end_x = snapshot.x_for_point(end, &text_layout_details) - scroll_left; Some(Bounds::from_corners( diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index ab9aa2ccf3adbf1b9fa244d65d841c184d77c4cc..0e53aa449d4d5bcc13626cf014f92511776f7481 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -1468,6 +1468,7 @@ impl EditorElement { gutter_margin = Pixels::ZERO; }; + editor.gutter_width = gutter_width; let text_width = bounds.size.width - gutter_width; let overscroll = size(em_width, px(0.)); let snapshot = {