Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Keep deleted gutter markers visible at narrow widths (#64469)

Rajin Khan189839eef500
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index 0320af6ab8b..4e96f08d17c 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -5519,20 +5519,32 @@ impl EditorElement {
});
}
- const DELETED_MARKER_WIDTH_RATIO: f32 = 0.35 / 0.275;
+ const DEFAULT_STRIP_WIDTH_RATIO: f32 = 0.275;
+ const DELETED_MARKER_WIDTH_RATIO: f32 = 0.35 / Self::DEFAULT_STRIP_WIDTH_RATIO;
+ const MIN_DELETED_MARKER_WIDTH_RATIO: f32 = 0.2;
fn gutter_strip_width(line_height: Pixels, cx: &App) -> Pixels {
match EditorSettings::get_global(cx).gutter.git_gutter_width {
GitGutterWidth::Custom(width) => px(*width),
- GitGutterWidth::Default => (0.275 * line_height).floor(),
+ GitGutterWidth::Default => (Self::DEFAULT_STRIP_WIDTH_RATIO * line_height).floor(),
}
}
fn deleted_marker_base_width(setting: GitGutterWidth, line_height: Pixels) -> Pixels {
match setting {
- GitGutterWidth::Custom(width) => px(*width * Self::DELETED_MARKER_WIDTH_RATIO),
+ GitGutterWidth::Custom(width) => {
+ let scaled_width = px(*width * Self::DELETED_MARKER_WIDTH_RATIO);
+ if scaled_width > Pixels::ZERO {
+ let default_strip_width = Self::DEFAULT_STRIP_WIDTH_RATIO * line_height;
+ let boost_factor = (1.0 - *width / f32::from(default_strip_width)).max(0.0);
+ scaled_width + line_height * Self::MIN_DELETED_MARKER_WIDTH_RATIO * boost_factor
+ } else {
+ Pixels::ZERO
+ }
+ }
GitGutterWidth::Default => {
- (0.275 * line_height * Self::DELETED_MARKER_WIDTH_RATIO).floor()
+ (Self::DEFAULT_STRIP_WIDTH_RATIO * line_height * Self::DELETED_MARKER_WIDTH_RATIO)
+ .floor()
}
}
}
@@ -13687,6 +13699,31 @@ mod tests {
"boosted={boosted:?} must exceed the raw custom width so the deleted pill stays visible"
);
+ for line_height in [22.0, 40.0] {
+ let widths = [1.0, 2.0, 3.0, 6.0].map(|width| {
+ EditorElement::deleted_marker_base_width(
+ GitGutterWidth::Custom(PixelSetting(width)),
+ px(line_height),
+ )
+ });
+ assert!(
+ widths.windows(2).all(|pair| pair[0] < pair[1]),
+ "widths={widths:?} must grow with the custom setting"
+ );
+ assert!(
+ widths[0] > px(line_height / 8.0),
+ "widths={widths:?} must stay above the vanishing width for line_height={line_height}"
+ );
+ }
+
+ assert_eq!(
+ EditorElement::deleted_marker_base_width(
+ GitGutterWidth::Custom(PixelSetting(0.275 * 40.0)),
+ px(40.0),
+ ),
+ px(14.0),
+ );
+
assert_eq!(
EditorElement::deleted_marker_base_width(
GitGutterWidth::Custom(PixelSetting(0.0)),