From ea02a95cf005fd2df64468cd3245aca99dc2ccac Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 10:48:36 +0100 Subject: [PATCH] editor: Hide horizontal scrollbar if not visible (cherry-pick #23337) (#23339) Cherry-picked editor: Hide horizontal scrollbar if not visible (#23337) This PR fixes two visual issues, that were caused by the fact that we were always painting the horizontal scrollbar even if there is no horizontal scrolling possible Obscuring deleted lines when using the inline assistant: https://github.com/user-attachments/assets/f8460c3f-403e-40a6-8622-65268ba2d875 Cutting off text even when horizontal scrolling is not possible: https://github.com/user-attachments/assets/23c909f7-1c23-4693-8edc-40a2f089d4a8 This issue was only present in some themes (e.g. Nord, Catpuccin) Closes #22716 Release Notes: - Fixed an issue where horizontal scrollbars of editors would always be painted (even if there is no horizontal scrolling to be done) Co-authored-by: Bennet Bo Fenner --- crates/assistant/src/inline_assistant.rs | 1 + crates/assistant2/src/inline_assistant.rs | 1 + crates/editor/src/element.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/assistant/src/inline_assistant.rs b/crates/assistant/src/inline_assistant.rs index 8acdaec50f4cfed05668ab34099979f842bb7620..c9955cb9b49968ed7587b972bfdf874c392e63ab 100644 --- a/crates/assistant/src/inline_assistant.rs +++ b/crates/assistant/src/inline_assistant.rs @@ -1204,6 +1204,7 @@ impl InlineAssistant { editor.set_show_wrap_guides(false, cx); editor.set_show_gutter(false, cx); editor.scroll_manager.set_forbid_vertical_scroll(true); + editor.set_show_scrollbars(false, cx); editor.set_read_only(true); editor.set_show_inline_completions(Some(false), cx); editor.highlight_rows::( diff --git a/crates/assistant2/src/inline_assistant.rs b/crates/assistant2/src/inline_assistant.rs index 73e539473f9bffb52562562cf6f88a34eb863151..bc90345883b6e6e4e1228e468f2ba46f9fd7a850 100644 --- a/crates/assistant2/src/inline_assistant.rs +++ b/crates/assistant2/src/inline_assistant.rs @@ -1276,6 +1276,7 @@ impl InlineAssistant { editor.set_show_wrap_guides(false, cx); editor.set_show_gutter(false, cx); editor.scroll_manager.set_forbid_vertical_scroll(true); + editor.set_show_scrollbars(false, cx); editor.set_read_only(true); editor.set_show_inline_completions(Some(false), cx); editor.highlight_rows::( diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index c5a64c7651bd93af2016af7224c9891706caca3a..374e223ab91ca6f4640608de001d78c520e726d0 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1333,11 +1333,15 @@ impl EditorElement { total_text_units .horizontal .zip(track_bounds.horizontal) - .map(|(total_text_units_x, track_bounds_x)| { + .and_then(|(total_text_units_x, track_bounds_x)| { + if text_units_per_page.horizontal >= total_text_units_x { + return None; + } + let thumb_percent = (text_units_per_page.horizontal / total_text_units_x).min(1.); - track_bounds_x.size.width * thumb_percent + Some(track_bounds_x.size.width * thumb_percent) }), total_text_units.vertical.zip(track_bounds.vertical).map( |(total_text_units_y, track_bounds_y)| {