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(
"Editor",
Some(size(px(1200.), px(960.))),
Some(size(px(1200.), px(750.))),
|window, cx| cx.new(|cx| Example::new(window, 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 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,

View file

@ -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<Pixels>,
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)
}