From bbea043d428053a3e00c3c633db3d299ff3282d8 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 11 Mar 2025 16:14:00 -0700 Subject: [PATCH] Git panel editor scroll (cherry-pick #26465) (#26493) Cherry-picked Git panel editor scroll (#26465) Release Notes: - N/A Co-authored-by: Conrad Irwin --- crates/git_ui/src/git_panel.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index dc25b917d9da576309f707ed6cb243c4f18aa82a..f5920d0079ea3154bd4002cd19a1677fabbd05e7 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -269,6 +269,8 @@ impl Drop for RemoteOperationGuard { } } +const MAX_PANEL_EDITOR_LINES: usize = 6; + pub(crate) fn commit_message_editor( commit_message_buffer: Entity, placeholder: Option<&str>, @@ -278,7 +280,7 @@ pub(crate) fn commit_message_editor( cx: &mut Context<'_, Editor>, ) -> Editor { let buffer = cx.new(|cx| MultiBuffer::singleton(commit_message_buffer, cx)); - let max_lines = if in_panel { 6 } else { 18 }; + let max_lines = if in_panel { MAX_PANEL_EDITOR_LINES } else { 18 }; let mut commit_editor = Editor::new( EditorMode::AutoHeight { max_lines }, buffer, @@ -2522,8 +2524,12 @@ impl GitPanel { let branch = active_repository.read(cx).current_branch().cloned(); let footer_size = px(32.); - let gap = px(8.0); - let max_height = window.line_height() * 5. + gap + footer_size; + let gap = px(9.0); + let max_height = panel_editor_style + .text + .line_height_in_pixels(window.rem_size()) + * MAX_PANEL_EDITOR_LINES + + gap; let git_panel = cx.entity().clone(); let display_name = SharedString::from(Arc::from( @@ -2532,6 +2538,9 @@ impl GitPanel { .display_name(project, cx) .trim_end_matches("/"), )); + let editor_is_long = self.commit_editor.update(cx, |editor, cx| { + editor.max_point(cx).row().0 >= MAX_PANEL_EDITOR_LINES as u32 + }); let footer = v_flex() .child(PanelRepoFooter::new( @@ -2544,11 +2553,10 @@ impl GitPanel { panel_editor_container(window, cx) .id("commit-editor-container") .relative() - .h(max_height) .w_full() + .h(max_height + footer_size) .border_t_1() .border_color(cx.theme().colors().border_variant) - .bg(cx.theme().colors().editor_background) .cursor_text() .on_click(cx.listener(move |this, _: &ClickEvent, window, cx| { window.focus(&this.commit_editor.focus_handle(cx)); @@ -2556,6 +2564,10 @@ impl GitPanel { .child( h_flex() .id("commit-footer") + .border_t_1() + .when(editor_is_long, |el| { + el.border_color(cx.theme().colors().border_variant) + }) .absolute() .bottom_0() .left_0()