editor: Fix indent guides render position. (#1524)

This commit is contained in:
Jason Lee 2025-11-05 21:17:32 +08:00 committed by GitHub
parent 998a5fd922
commit 4b3fb51fb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 6 deletions

View file

@ -1041,7 +1041,7 @@ fn main() {
story::create_new_window_with_size( story::create_new_window_with_size(
"Editor", "Editor",
Some(size(px(1200.), px(960.))), Some(size(px(1200.), px(750.))),
|window, cx| cx.new(|cx| Example::new(window, cx)), |window, cx| cx.new(|cx| Example::new(window, cx)),
cx, cx,
); );

View file

@ -1085,7 +1085,7 @@ impl Element for TextElement {
let hover_definition_hitbox = self.layout_hover_definition_hitbox(state, window, cx); let hover_definition_hitbox = self.layout_hover_definition_hitbox(state, window, cx);
let indent_guides_path = let indent_guides_path =
self.layout_indent_guides(state, &last_layout, &text_style, window); self.layout_indent_guides(state, &bounds, &last_layout, &text_style, window);
PrepaintState { PrepaintState {
bounds, bounds,

View file

@ -1,6 +1,6 @@
use gpui::{ use gpui::{
point, px, Context, EntityInputHandler as _, Hsla, Path, PathBuilder, Pixels, SharedString, point, px, Bounds, Context, EntityInputHandler as _, Hsla, Path, PathBuilder, Pixels,
TextRun, TextStyle, Window, SharedString, TextRun, TextStyle, Window,
}; };
use ropey::RopeSlice; use ropey::RopeSlice;
@ -104,6 +104,7 @@ impl TextElement {
pub(super) fn layout_indent_guides( pub(super) fn layout_indent_guides(
&self, &self,
state: &InputState, state: &InputState,
bounds: &Bounds<Pixels>,
last_layout: &LastLayout, last_layout: &LastLayout,
text_style: &TextStyle, text_style: &TextStyle,
window: &mut Window, window: &mut Window,
@ -119,8 +120,7 @@ impl TextElement {
let line_height = last_layout.line_height; let line_height = last_layout.line_height;
let visible_range = last_layout.visible_range.clone(); let visible_range = last_layout.visible_range.clone();
let mut builder = PathBuilder::stroke(px(1.)); let mut builder = PathBuilder::stroke(px(1.));
let mut offset_y = let mut offset_y = last_layout.visible_top;
last_layout.visible_top + state.scroll_handle.offset().y + (line_height * 2 - px(3.5));
let mut last_indents = vec![]; let mut last_indents = vec![];
for ix in visible_range { for ix in visible_range {
let line = state.text.slice_line(ix); let line = state.text.slice_line(ix);
@ -154,6 +154,7 @@ impl TextElement {
last_indents = current_indents; last_indents = current_indents;
} }
builder.translate(bounds.origin);
let path = builder.build().unwrap(); let path = builder.build().unwrap();
Some(path) Some(path)
} }