From 1035c6aab5700535c8b32b17cfaa67379bdfacfc Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Wed, 28 May 2025 21:59:51 +0200 Subject: [PATCH] editor: Fix horizontal scrollbar alignment if indent guides are disabled (#31621) Follow-up to #24887 Follow-up to #31510 This PR ensures that [this misalignment of the horizontal scrollbar](https://github.com/zed-industries/zed/pull/31510#issuecomment-2912842457) does not occur. See the entire discussion in the first linked PR as to why this gap is there in the first place. I am also aware of the general stance towards comments. Yet, I felt for this case it is better to just straight up explain how these two things are connected, as I do believe this is not intuitively clear after all. Might also be a good time to bring https://github.com/zed-industries/zed/issues/25519 up again. The horizontal scrollbar seems huge for the edit file tool card. Furthermore, since we do not reserve space for the horizontal scrollbar (yet), this will lead to the last line being not clickable. Release Notes: - N/A --- crates/editor/src/element.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 915524f932..b1eabec4b5 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1512,6 +1512,17 @@ impl EditorElement { ShowScrollbar::Never => return None, }; + // The horizontal scrollbar is usually slightly offset to align nicely with + // indent guides. However, this offset is not needed if indent guides are + // disabled for the current editor. + let content_offset = self + .editor + .read(cx) + .show_indent_guides + .is_none_or(|should_show| should_show) + .then_some(content_offset) + .unwrap_or_default(); + Some(EditorScrollbars::from_scrollbar_axes( ScrollbarAxes { horizontal: scrollbar_settings.axes.horizontal