From bb97432e9a2343b714781200a1bb02576285bf85 Mon Sep 17 00:00:00 2001 From: Shreekar Halvi <53833237+hshreekar@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:58:47 +0530 Subject: [PATCH] Add minimum column option to git inline blame (#10682) Release Notes: - Added a setting to determine the minimum column where the inline blame information is shown. Example: `{{"git": {"inline_blame": {"min_column": 80}}}` ([#10555](https://github.com/zed-industries/zed/issues/10555)). Demo Video: https://github.com/zed-industries/zed/assets/1185253/61343dbe-9002-4bd1-b0d4-403f8da79050 --------- Co-authored-by: Thorsten Ball --- crates/collab/src/tests/editor_tests.rs | 1 + crates/editor/src/element.rs | 15 ++++++++++++--- crates/project/src/project_settings.rs | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index 99ef30b21c3d3617d067fc9737459bee973007ae..1706cb4a8b986e7bb17acfdf4bf0618e7288c290 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -2006,6 +2006,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA let inline_blame_off_settings = Some(InlineBlameSettings { enabled: false, delay_ms: None, + min_column: None, }); cx_a.update(|cx| { cx.update_global(|store: &mut SettingsStore, cx| { diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index f327787263d848238a4c6a3f4a295949b6682b7d..199d0294e60915d11ddddc111c7570ab724b728d 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -45,7 +45,7 @@ use smallvec::SmallVec; use std::{ any::TypeId, borrow::Cow, - cmp::{self, Ordering}, + cmp::{self, max, Ordering}, fmt::Write, iter, mem, ops::Range, @@ -1141,8 +1141,17 @@ impl EditorElement { let start_x = { const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.; - let line_width = line_layout.line.width; - content_origin.x + line_width + (em_width * INLINE_BLAME_PADDING_EM_WIDTHS) + let padded_line_width = + line_layout.line.width + (em_width * INLINE_BLAME_PADDING_EM_WIDTHS); + + let min_column = ProjectSettings::get_global(cx) + .git + .inline_blame + .and_then(|settings| settings.min_column) + .map(|col| self.column_pixels(col as usize, cx)) + .unwrap_or(px(0.)); + + content_origin.x + max(padded_line_width, min_column) }; let absolute_offset = point(start_x, start_y); diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index 579c8e6156723e7604df65ea9efab6925e2abbb4..b49331545545983ca2ede07749f481675907757b 100644 --- a/crates/project/src/project_settings.rs +++ b/crates/project/src/project_settings.rs @@ -79,6 +79,10 @@ pub struct InlineBlameSettings { /// /// Default: 0 pub delay_ms: Option, + /// The minimum column number to show the inline blame information at + /// + /// Default: 0 + pub min_column: Option, } const fn true_value() -> bool {