Fix vertical position in first_rect_for_character_range

This commit is contained in:
Max Brunsfeld 2023-11-08 17:27:32 -08:00
parent 86865431b9
commit 277fbda356
2 changed files with 14 additions and 16 deletions

View file

@ -39,11 +39,11 @@ use futures::FutureExt;
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use git::diff_hunk_to_display; use git::diff_hunk_to_display;
use gpui::{ use gpui::{
action, actions, div, point, px, relative, AnyElement, AppContext, BackgroundExecutor, Bounds, action, actions, div, point, px, relative, size, AnyElement, AppContext, BackgroundExecutor,
ClipboardItem, Context, DispatchContext, Div, Element, Entity, EventEmitter, FocusHandle, Bounds, ClipboardItem, Context, DispatchContext, Div, Element, Entity, EventEmitter,
FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels, PlatformInputHandler, FocusHandle, FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels,
Render, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, WeakView, PlatformInputHandler, Render, Styled, Subscription, Task, TextStyle, View, ViewContext,
WindowContext, VisualContext, WeakView, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState}; use hover_popover::{hide_hover, HoverState};
@ -9774,17 +9774,13 @@ impl InputHandler for Editor {
let scroll_left = scroll_position.x * em_width; let scroll_left = scroll_position.x * em_width;
let start = OffsetUtf16(range_utf16.start).to_display_point(&snapshot); let start = OffsetUtf16(range_utf16.start).to_display_point(&snapshot);
let end = OffsetUtf16(range_utf16.end).to_display_point(&snapshot); let x = snapshot.x_for_point(start, &text_layout_details) - scroll_left + self.gutter_width;
let start_y = line_height * (start.row() as f32 - scroll_position.y); let 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;
Some(Bounds::from_corners( Some(Bounds {
element_bounds.origin + point(start_x, start_y), origin: element_bounds.origin + point(x, y),
element_bounds.origin + point(end_x, end_y), size: size(em_width, line_height),
)) })
} }
} }

View file

@ -1485,7 +1485,9 @@ extern "C" fn first_rect_for_character_range(
NSRect::new( NSRect::new(
NSPoint::new( NSPoint::new(
frame.origin.x + bounds.origin.x.0 as f64, 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), NSSize::new(bounds.size.width.0 as f64, bounds.size.height.0 as f64),
) )