Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
terminal_view: Fix inline terminal clipping its first line of output (#61939)
Tim Vermeulen0b3621db4789
diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rsindex f580e769dd1..f3d37d357dc 100644--- a/crates/terminal_view/src/terminal_element.rs+++ b/crates/terminal_view/src/terminal_element.rs@@ -1153,7 +1153,11 @@ impl Element for TerminalElement {let rem_size = window.rem_size();let line_height = f32::from(window.text_style().font_size.to_pixels(rem_size))* TerminalSettings::get_global(cx).line_height.value();- px(displayed_lines as f32 * line_height).into()+ // Round up to a whole device pixel to prevent pixel snapping from rounding down,+ // which would result in the terminal being one row short after flooring.+ let scale_factor = window.scale_factor().max(1.);+ let height = displayed_lines as f32 * line_height;+ px((height * scale_factor).ceil() / scale_factor).into()}ContentMode::Scrollable => {if let TerminalMode::Embedded { .. } = &self.mode {diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex 3dad6134174..1f380c8aac5 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -3126,6 +3126,48 @@ mod tests {assert_eq!(bounds.bottom(), draw_size.height);}+ #[gpui::test]+ async fn test_inline_terminal_displays_all_of_its_lines(cx: &mut TestAppContext) {+ let (project, workspace) = init_test(cx).await;+ let terminal = cx.new(|cx| {+ terminal::TerminalBuilder::new_display_only(+ CursorShape::default(),+ terminal::terminal_settings::AlternateScroll::On,+ None,+ 0,+ cx.background_executor(),+ PathStyle::local(),+ )+ .subscribe(cx)+ });+ let (terminal_view, cx) = cx.add_window_view(|window, cx| {+ let mut terminal_view = TerminalView::new(+ terminal.clone(),+ workspace.downgrade(),+ None,+ project.downgrade(),+ window,+ cx,+ );+ terminal_view.set_embedded_mode(None, cx);+ terminal_view+ });++ for _ in 1..=20 {+ terminal.update(cx, |terminal, cx| {+ terminal.write_output(b"line\n", cx);+ });+ cx.draw(+ gpui::Point::default(),+ gpui::size(px(400.), px(100.)),+ |_, _| terminal_view.clone().into_any_element(),+ );+ terminal.read_with(cx, |terminal, _| {+ assert_eq!(terminal.viewport_lines(), terminal.total_lines());+ })+ }+ }+#[gpui::test]async fn test_tab_content_shows_terminal_title_when_custom_title_directly_set_empty(cx: &mut TestAppContext,