From 4b3fb51fb8e7241433e1db953db4ff379ce78aa4 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 5 Nov 2025 21:17:32 +0800 Subject: [PATCH] editor: Fix indent guides render position. (#1524) --- crates/story/examples/editor.rs | 2 +- crates/ui/src/input/element.rs | 2 +- crates/ui/src/input/indent.rs | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/story/examples/editor.rs b/crates/story/examples/editor.rs index 79fbdd28..48cb0baf 100644 --- a/crates/story/examples/editor.rs +++ b/crates/story/examples/editor.rs @@ -1041,7 +1041,7 @@ fn main() { story::create_new_window_with_size( "Editor", - Some(size(px(1200.), px(960.))), + Some(size(px(1200.), px(750.))), |window, cx| cx.new(|cx| Example::new(window, cx)), cx, ); diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index 703d9889..91bfbca4 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -1085,7 +1085,7 @@ impl Element for TextElement { let hover_definition_hitbox = self.layout_hover_definition_hitbox(state, window, cx); 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 { bounds, diff --git a/crates/ui/src/input/indent.rs b/crates/ui/src/input/indent.rs index ba0519e3..67492dba 100644 --- a/crates/ui/src/input/indent.rs +++ b/crates/ui/src/input/indent.rs @@ -1,6 +1,6 @@ use gpui::{ - point, px, Context, EntityInputHandler as _, Hsla, Path, PathBuilder, Pixels, SharedString, - TextRun, TextStyle, Window, + point, px, Bounds, Context, EntityInputHandler as _, Hsla, Path, PathBuilder, Pixels, + SharedString, TextRun, TextStyle, Window, }; use ropey::RopeSlice; @@ -104,6 +104,7 @@ impl TextElement { pub(super) fn layout_indent_guides( &self, state: &InputState, + bounds: &Bounds, last_layout: &LastLayout, text_style: &TextStyle, window: &mut Window, @@ -119,8 +120,7 @@ impl TextElement { let line_height = last_layout.line_height; let visible_range = last_layout.visible_range.clone(); let mut builder = PathBuilder::stroke(px(1.)); - let mut offset_y = - last_layout.visible_top + state.scroll_handle.offset().y + (line_height * 2 - px(3.5)); + let mut offset_y = last_layout.visible_top; let mut last_indents = vec![]; for ix in visible_range { let line = state.text.slice_line(ix); @@ -154,6 +154,7 @@ impl TextElement { last_indents = current_indents; } + builder.translate(bounds.origin); let path = builder.build().unwrap(); Some(path) }