@@ -23,7 +23,7 @@ use crate::{
23
23
InlineCompletion , JumpData , LineDown , LineHighlight , LineUp , OpenExcerpts , PageDown , PageUp ,
24
24
Point , RowExt , RowRangeExt , SelectPhase , SelectedTextHighlight , Selection , SoftWrap ,
25
25
StickyHeaderExcerpt , ToPoint , ToggleFold , COLUMNAR_SELECTION_MODIFIERS , CURSORS_VISIBLE_FOR ,
26
- FILE_HEADER_HEIGHT , GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED , MAX_LINE_LEN ,
26
+ FILE_HEADER_HEIGHT , GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED , MAX_LINE_LEN , MIN_LINE_NUMBER_DIGITS ,
27
27
MULTI_BUFFER_EXCERPT_HEADER_HEIGHT ,
28
28
} ;
29
29
use buffer_diff:: { DiffHunkStatus , DiffHunkStatusKind } ;
@@ -2119,9 +2119,11 @@ impl EditorElement {
2119
2119
} )
2120
2120
}
2121
2121
2122
- fn layout_excerpt_gutter (
2122
+ fn layout_expand_toggles (
2123
2123
& self ,
2124
2124
gutter_hitbox : & Hitbox ,
2125
+ gutter_dimensions : GutterDimensions ,
2126
+ em_width : Pixels ,
2125
2127
line_height : Pixels ,
2126
2128
scroll_position : gpui:: Point < f32 > ,
2127
2129
buffer_rows : & [ RowInfo ] ,
@@ -2130,19 +2132,17 @@ impl EditorElement {
2130
2132
) -> Vec < Option < ( AnyElement , gpui:: Point < Pixels > ) > > {
2131
2133
let editor_font_size = self . style . text . font_size . to_pixels ( window. rem_size ( ) ) * 1.2 ;
2132
2134
2133
- let icon_size = editor_font_size. round ( ) ;
2134
- let button_h_padding = ( ( icon_size - px ( 1.0 ) ) / 2.0 ) . round ( ) - px ( 2.0 ) ;
2135
-
2136
2135
let scroll_top = scroll_position. y * line_height;
2137
2136
2138
- let max_line_number_length = 1 + self
2137
+ let max_line_number_length = self
2139
2138
. editor
2140
2139
. read ( cx)
2141
2140
. buffer ( )
2142
2141
. read ( cx)
2143
2142
. snapshot ( cx)
2144
2143
. widest_line_number ( )
2145
- . ilog10 ( ) ;
2144
+ . ilog10 ( )
2145
+ + 1 ;
2146
2146
2147
2147
let elements = buffer_rows
2148
2148
. into_iter ( )
@@ -2159,20 +2159,27 @@ impl EditorElement {
2159
2159
ExpandExcerptDirection :: UpAndDown => IconName :: ExpandVertical ,
2160
2160
} ;
2161
2161
2162
+ let git_gutter_width = Self :: gutter_strip_width ( line_height) ;
2163
+ let available_width = gutter_dimensions. left_padding - git_gutter_width;
2164
+
2162
2165
let editor = self . editor . clone ( ) ;
2163
- let is_wide = max_line_number_length > 3
2166
+ let is_wide = max_line_number_length >= MIN_LINE_NUMBER_DIGITS
2164
2167
&& row_info
2165
2168
. buffer_row
2166
- . is_some_and ( |row| ( row + 1 ) . ilog10 ( ) + 1 == max_line_number_length) ;
2169
+ . is_some_and ( |row| ( row + 1 ) . ilog10 ( ) + 1 == max_line_number_length)
2170
+ || gutter_dimensions. right_padding == px ( 0. ) ;
2171
+
2172
+ let width = if is_wide {
2173
+ available_width - px ( 2. )
2174
+ } else {
2175
+ available_width + em_width - px ( 2. )
2176
+ } ;
2167
2177
2168
2178
let toggle = IconButton :: new ( ( "expand" , ix) , icon_name)
2169
2179
. icon_color ( Color :: Custom ( cx. theme ( ) . colors ( ) . editor_line_number ) )
2170
2180
. selected_icon_color ( Color :: Custom ( cx. theme ( ) . colors ( ) . editor_foreground ) )
2171
2181
. icon_size ( IconSize :: Custom ( rems ( editor_font_size / window. rem_size ( ) ) ) )
2172
- . width ( ( icon_size + button_h_padding * 2 ) . into ( ) )
2173
- . when ( is_wide, |el| {
2174
- el. width ( ( icon_size + button_h_padding) . into ( ) )
2175
- } )
2182
+ . width ( width. into ( ) )
2176
2183
. on_click ( move |_, _, cx| {
2177
2184
editor. update ( cx, |editor, cx| {
2178
2185
editor. expand_excerpt ( excerpt_id, direction, cx) ;
@@ -2185,7 +2192,7 @@ impl EditorElement {
2185
2192
. into_any_element ( ) ;
2186
2193
2187
2194
let position = point (
2188
- px ( 1. ) ,
2195
+ git_gutter_width + px ( 1. ) ,
2189
2196
ix as f32 * line_height - ( scroll_top % line_height) + px ( 1. ) ,
2190
2197
) ;
2191
2198
let origin = gutter_hitbox. origin + position;
@@ -2709,7 +2716,7 @@ impl EditorElement {
2709
2716
for_excerpt : & ExcerptInfo ,
2710
2717
is_folded : bool ,
2711
2718
is_selected : bool ,
2712
- _is_sticky : bool ,
2719
+ is_sticky : bool ,
2713
2720
jump_data : JumpData ,
2714
2721
window : & mut Window ,
2715
2722
cx : & mut App ,
@@ -2744,8 +2751,7 @@ impl EditorElement {
2744
2751
let colors = cx. theme ( ) . colors ( ) ;
2745
2752
2746
2753
div ( )
2747
- . px_2 ( )
2748
- . pt_2 ( )
2754
+ . p_1 ( )
2749
2755
. w_full ( )
2750
2756
. h ( FILE_HEADER_HEIGHT as f32 * window. line_height ( ) )
2751
2757
. child (
@@ -2756,7 +2762,7 @@ impl EditorElement {
2756
2762
. pl_0p5 ( )
2757
2763
. pr_5 ( )
2758
2764
. rounded_sm ( )
2759
- // .when(is_sticky, |el| el.shadow_md())
2765
+ . when ( is_sticky, |el| el. shadow_md ( ) )
2760
2766
. border_1 ( )
2761
2767
. map ( |div| {
2762
2768
let border_color = if is_selected
@@ -2784,7 +2790,7 @@ impl EditorElement {
2784
2790
ButtonLike :: new ( "toggle-buffer-fold" )
2785
2791
. style ( ui:: ButtonStyle :: Transparent )
2786
2792
. size ( ButtonSize :: Large )
2787
- . width ( px ( 30 .) . into ( ) )
2793
+ . width ( px ( 24 .) . into ( ) )
2788
2794
. children ( toggle_chevron_icon)
2789
2795
. tooltip ( {
2790
2796
let focus_handle = focus_handle. clone ( ) ;
@@ -4413,6 +4419,10 @@ impl EditorElement {
4413
4419
} ) ;
4414
4420
}
4415
4421
4422
+ fn gutter_strip_width ( line_height : Pixels ) -> Pixels {
4423
+ ( 0.275 * line_height) . floor ( )
4424
+ }
4425
+
4416
4426
fn diff_hunk_bounds (
4417
4427
snapshot : & EditorSnapshot ,
4418
4428
line_height : Pixels ,
@@ -4421,7 +4431,7 @@ impl EditorElement {
4421
4431
) -> Bounds < Pixels > {
4422
4432
let scroll_position = snapshot. scroll_position ( ) ;
4423
4433
let scroll_top = scroll_position. y * line_height;
4424
- let gutter_strip_width = ( 0.275 * line_height) . floor ( ) ;
4434
+ let gutter_strip_width = Self :: gutter_strip_width ( line_height) ;
4425
4435
4426
4436
match hunk {
4427
4437
DisplayDiffHunk :: Folded { display_row, .. } => {
@@ -6887,8 +6897,10 @@ impl Element for EditorElement {
6887
6897
6888
6898
let mut expand_toggles =
6889
6899
window. with_element_namespace ( "expand_toggles" , |window| {
6890
- self . layout_excerpt_gutter (
6900
+ self . layout_expand_toggles (
6891
6901
& gutter_hitbox,
6902
+ gutter_dimensions,
6903
+ em_width,
6892
6904
line_height,
6893
6905
scroll_position,
6894
6906
& row_infos,
0 commit comments