git: Make inline blame padding configurable (#33631)
Just like with diagnostics, adding a configurable padding to inline blame Release Notes: - Added configurable padding to inline blame --------- Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Peter Tripp <petertripp@gmail.com>
This commit is contained in:
parent
35cd1b9ae1
commit
cdfb3348ea
6 changed files with 60 additions and 19 deletions
|
@ -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 at
|
||||
|
|
|
@ -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 so
|
||||
let 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| {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue