Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git: Make inline blame padding configurable (#33631)
Abdelhakim Qbaichcdfb3348ea0a
diff --git a/assets/settings/default.json b/assets/settings/default.jsonindex 4734b5d1188..d69fd58009d 100644--- a/assets/settings/default.json+++ b/assets/settings/default.json@@ -1171,6 +1171,9 @@// Sets a delay after which the inline blame information is shown.// Delay is restarted with every cursor movement."delay_ms": 0,+ // The amount of padding between the end of the source line and the start+ // of the inline blame in units of em widths.+ "padding": 7,// Whether or not to display the git commit summary on the same line."show_commit_summary": false,// The minimum column number to show the inline blame information atdiff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rsindex 8754b53f6ea..7b95fdd4580 100644--- a/crates/collab/src/tests/editor_tests.rs+++ b/crates/collab/src/tests/editor_tests.rs@@ -3101,9 +3101,7 @@ async fn test_git_blame_is_forwarded(cx_a: &mut TestAppContext, cx_b: &mut TestA// Turn inline-blame-off by default so no state is transferred without us explicitly doing solet inline_blame_off_settings = Some(InlineBlameSettings {enabled: false,- delay_ms: None,- min_column: None,- show_commit_summary: false,+ ..Default::default()});cx_a.update(|cx| {SettingsStore::update_global(cx, |store, cx| {diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 428a30471dd..a7fd0abf882 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -86,8 +86,6 @@ use util::post_inc;use util::{RangeExt, ResultExt, debug_panic};use workspace::{CollaboratorId, Workspace, item::Item, notifications::NotifyTaskExt};-const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 7.;-/// Determines what kinds of highlights should be applied to a lines background.#[derive(Clone, Copy, Default)]struct LineHighlightSpec {@@ -2428,10 +2426,13 @@ impl EditorElement {let editor = self.editor.read(cx);let blame = editor.blame.clone()?;let padding = {- const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.;const INLINE_ACCEPT_SUGGESTION_EM_WIDTHS: f32 = 14.;- let mut padding = INLINE_BLAME_PADDING_EM_WIDTHS;+ let mut padding = ProjectSettings::get_global(cx)+ .git+ .inline_blame+ .unwrap_or_default()+ .padding as f32;if let Some(edit_prediction) = editor.active_edit_prediction.as_ref() {match &edit_prediction.completion {@@ -2469,7 +2470,7 @@ impl EditorElement {let min_column_in_pixels = ProjectSettings::get_global(cx).git.inline_blame- .and_then(|settings| settings.min_column)+ .map(|settings| settings.min_column).map(|col| self.column_pixels(col as usize, window)).unwrap_or(px(0.));let min_start = content_origin.x - scroll_pixel_position.x + min_column_in_pixels;@@ -8365,7 +8366,13 @@ impl Element for EditorElement {}).flatten()?;let mut element = render_inline_blame_entry(blame_entry, &style, cx)?;- let inline_blame_padding = INLINE_BLAME_PADDING_EM_WIDTHS * em_advance;+ let inline_blame_padding = ProjectSettings::get_global(cx)+ .git+ .inline_blame+ .unwrap_or_default()+ .padding+ as f32+ * em_advance;Some(element.layout_as_root(AvailableSpace::min_size(), window, cx)diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rsindex 20be7fef85c..12e3aa88ad6 100644--- a/crates/project/src/project_settings.rs+++ b/crates/project/src/project_settings.rs@@ -431,10 +431,9 @@ impl GitSettings {pub fn inline_blame_delay(&self) -> Option<Duration> {match self.inline_blame {- Some(InlineBlameSettings {- delay_ms: Some(delay_ms),- ..- }) if delay_ms > 0 => Some(Duration::from_millis(delay_ms)),+ Some(InlineBlameSettings { delay_ms, .. }) if delay_ms > 0 => {+ Some(Duration::from_millis(delay_ms))+ }_ => None,}}@@ -470,7 +469,7 @@ pub enum GitGutterSetting {Hide,}-#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]+#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]#[serde(rename_all = "snake_case")]pub struct InlineBlameSettings {/// Whether or not to show git blame data inline in@@ -483,11 +482,19 @@ pub struct InlineBlameSettings {/// after a delay once the cursor stops moving.////// Default: 0- pub delay_ms: Option<u64>,+ #[serde(default)]+ pub delay_ms: u64,+ /// The amount of padding between the end of the source line and the start+ /// of the inline blame in units of columns.+ ///+ /// Default: 7+ #[serde(default = "default_inline_blame_padding")]+ pub padding: u32,/// The minimum column number to show the inline blame information at////// Default: 0- pub min_column: Option<u32>,+ #[serde(default)]+ pub min_column: u32,/// Whether to show commit summary as part of the inline blame.////// Default: false@@ -495,6 +502,22 @@ pub struct InlineBlameSettings {pub show_commit_summary: bool,}+fn default_inline_blame_padding() -> u32 {+ 7+}++impl Default for InlineBlameSettings {+ fn default() -> Self {+ Self {+ enabled: true,+ delay_ms: 0,+ padding: default_inline_blame_padding(),+ min_column: 0,+ show_commit_summary: false,+ }+ }+}+#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]pub struct BinarySettings {pub path: Option<String>,diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.mdindex 5fd27abad67..d2ca0e06044 100644--- a/docs/src/configuring-zed.md+++ b/docs/src/configuring-zed.md@@ -1795,7 +1795,6 @@ Example:{"git": {"inline_blame": {- "enabled": true,"delay_ms": 500}}@@ -1808,7 +1807,6 @@ Example:{"git": {"inline_blame": {- "enabled": true,"show_commit_summary": true}}@@ -1821,13 +1819,24 @@ Example:{"git": {"inline_blame": {- "enabled": true,"min_column": 80}}}```+5. Set the padding between the end of the line and the inline blame hint, in ems:++```json+{+ "git": {+ "inline_blame": {+ "padding": 10+ }+ }+}+```+### Hunk Style- Description: What styling we should use for the diff hunks.diff --git a/docs/src/visual-customization.md b/docs/src/visual-customization.mdindex 8b307d97d58..34ce067ebae 100644--- a/docs/src/visual-customization.md+++ b/docs/src/visual-customization.md@@ -223,6 +223,7 @@ TBD: Centered layout related settings"enabled": true, // Show/hide inline blame"delay": 0, // Show after delay (ms)"min_column": 0, // Minimum column to inline display blame+ "padding": 7, // Padding between code and inline blame (em)"show_commit_summary": false // Show/hide commit summary},"hunk_style": "staged_hollow" // staged_hollow, unstaged_hollow