From 277fbda35696802d4fb4ab6b2ce28009a1bec795 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 8 Nov 2023 17:27:32 -0800 Subject: [PATCH] Fix vertical position in first_rect_for_character_range --- crates/editor2/src/editor.rs | 26 +++++++++++-------------- crates/gpui2/src/platform/mac/window.rs | 4 +++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 8cc58a87bf..2b64aa2e8b 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -39,11 +39,11 @@ use futures::FutureExt; use fuzzy::{StringMatch, StringMatchCandidate}; use git::diff_hunk_to_display; use gpui::{ - action, actions, div, point, px, relative, AnyElement, AppContext, BackgroundExecutor, Bounds, - ClipboardItem, Context, DispatchContext, Div, Element, Entity, EventEmitter, FocusHandle, - FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels, PlatformInputHandler, - Render, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, WeakView, - WindowContext, + action, actions, div, point, px, relative, size, AnyElement, AppContext, BackgroundExecutor, + Bounds, ClipboardItem, Context, DispatchContext, Div, Element, Entity, EventEmitter, + FocusHandle, FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels, + PlatformInputHandler, Render, Styled, Subscription, Task, TextStyle, View, ViewContext, + VisualContext, WeakView, WindowContext, }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; @@ -9774,17 +9774,13 @@ impl InputHandler for Editor { let scroll_left = scroll_position.x * em_width; 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 + self.gutter_width; - let end_x = snapshot.x_for_point(end, &text_layout_details) - scroll_left; + let x = snapshot.x_for_point(start, &text_layout_details) - scroll_left + self.gutter_width; + let y = line_height * (start.row() as f32 - scroll_position.y); - Some(Bounds::from_corners( - element_bounds.origin + point(start_x, start_y), - element_bounds.origin + point(end_x, end_y), - )) + Some(Bounds { + origin: element_bounds.origin + point(x, y), + size: size(em_width, line_height), + }) } } diff --git a/crates/gpui2/src/platform/mac/window.rs b/crates/gpui2/src/platform/mac/window.rs index bd45178e97..d07df3d94b 100644 --- a/crates/gpui2/src/platform/mac/window.rs +++ b/crates/gpui2/src/platform/mac/window.rs @@ -1485,7 +1485,9 @@ extern "C" fn first_rect_for_character_range( NSRect::new( NSPoint::new( frame.origin.x + bounds.origin.x.0 as f64, - frame.origin.y + frame.size.height - bounds.origin.y.0 as f64, + frame.origin.y + frame.size.height + - bounds.origin.y.0 as f64 + - bounds.size.height.0 as f64, ), NSSize::new(bounds.size.width.0 as f64, bounds.size.height.0 as f64), )