Prevent scrollbar from covering bottom right text in terminal (#33636)

Closes https://github.com/zed-industries/zed/issues/27241

Release Notes:

- Fixed terminal scrollbar covering bottom right text by adding proper
content padding when scrollbar is visible

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
ddoemonn 2025-08-08 23:46:31 +03:00 committed by GitHub
parent e0fc32009f
commit fd1beedb16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -64,8 +64,8 @@ use std::{
}; };
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500); const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
const GIT_DIFF_PATH_PREFIXES: &[&str] = &["a", "b"]; const GIT_DIFF_PATH_PREFIXES: &[&str] = &["a", "b"];
const TERMINAL_SCROLLBAR_WIDTH: Pixels = px(12.);
/// Event to transmit the scroll from the element to the view /// Event to transmit the scroll from the element to the view
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
@ -956,13 +956,12 @@ impl TerminalView {
.on_scroll_wheel(cx.listener(|_, _, _window, cx| { .on_scroll_wheel(cx.listener(|_, _, _window, cx| {
cx.notify(); cx.notify();
})) }))
.h_full()
.absolute() .absolute()
.right_1() .top_0()
.top_1()
.bottom_0() .bottom_0()
.w(px(12.)) .right_0()
.cursor_default() .h_full()
.w(TERMINAL_SCROLLBAR_WIDTH)
.children(Scrollbar::vertical(self.scrollbar_state.clone())), .children(Scrollbar::vertical(self.scrollbar_state.clone())),
) )
} }
@ -1496,6 +1495,16 @@ impl Render for TerminalView {
let focused = self.focus_handle.is_focused(window); let focused = self.focus_handle.is_focused(window);
// Always calculate scrollbar width to prevent layout shift
let scrollbar_width = if Self::should_show_scrollbar(cx)
&& self.content_mode(window, cx).is_scrollable()
&& self.terminal.read(cx).total_lines() > self.terminal.read(cx).viewport_lines()
{
TERMINAL_SCROLLBAR_WIDTH
} else {
px(0.)
};
div() div()
.id("terminal-view") .id("terminal-view")
.size_full() .size_full()
@ -1545,6 +1554,8 @@ impl Render for TerminalView {
// TODO: Oddly this wrapper div is needed for TerminalElement to not steal events from the context menu // TODO: Oddly this wrapper div is needed for TerminalElement to not steal events from the context menu
div() div()
.size_full() .size_full()
.bg(cx.theme().colors().editor_background)
.when(scrollbar_width > px(0.), |div| div.pr(scrollbar_width))
.child(TerminalElement::new( .child(TerminalElement::new(
terminal_handle, terminal_handle,
terminal_view_handle, terminal_view_handle,