diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 3d88c69ebd..73de63bed2 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2698,52 +2698,67 @@ impl Editor { &self, fold_data: Option>, style: &EditorStyle, - _gutter_hovered: bool, + gutter_hovered: bool, + line_height: f32, + gutter_margin: f32, cx: &mut RenderContext, ) -> Option> { enum FoldIndicators {} + let style = style.folds.clone(); + fold_data.map(|fold_data| { fold_data .iter() .copied() - .map(|(fold_location, fold_status)| { - ( - fold_location, - MouseEventHandler::::new( - fold_location as usize, - cx, - |mouse_state, _| -> ElementBox { - Svg::new(match fold_status { - FoldStatus::Folded => "icons/chevron_right_8.svg", - FoldStatus::Foldable => "icons/chevron_down_8.svg", - }) - .with_color( - style - .folds - .indicator - .style_for(mouse_state, fold_status == FoldStatus::Folded) - .color, - ) - .boxed() - }, + .filter_map(|(fold_location, fold_status)| { + (gutter_hovered || fold_status == FoldStatus::Folded).then(|| { + ( + fold_location, + MouseEventHandler::::new( + fold_location as usize, + cx, + |mouse_state, _| -> ElementBox { + Svg::new(match fold_status { + FoldStatus::Folded => style.folded_icon.clone(), + FoldStatus::Foldable => style.foldable_icon.clone(), + }) + .with_color( + style + .indicator + .style_for( + mouse_state, + fold_status == FoldStatus::Folded, + ) + .color, + ) + .constrained() + .with_width(style.icon_width) + .aligned() + .constrained() + .with_height(line_height) + .with_width(gutter_margin) + .aligned() + .boxed() + }, + ) + .with_cursor_style(CursorStyle::PointingHand) + .with_padding(Padding::uniform(3.)) + .on_click(MouseButton::Left, { + move |_, cx| { + cx.dispatch_any_action(match fold_status { + FoldStatus::Folded => Box::new(UnfoldAt { + display_row: DisplayRow::new(fold_location), + }), + FoldStatus::Foldable => Box::new(FoldAt { + display_row: DisplayRow::new(fold_location), + }), + }); + } + }) + .boxed(), ) - .with_cursor_style(CursorStyle::PointingHand) - .with_padding(Padding::uniform(3.)) - .on_click(MouseButton::Left, { - move |_, cx| { - cx.dispatch_any_action(match fold_status { - FoldStatus::Folded => Box::new(UnfoldAt { - display_row: DisplayRow::new(fold_location), - }), - FoldStatus::Foldable => Box::new(FoldAt { - display_row: DisplayRow::new(fold_location), - }), - }); - } - }) - .boxed(), - ) + }) }) .collect() }) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 5b2e72999a..5f2a3670fe 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1829,7 +1829,14 @@ impl Element for EditorElement { hover = view.hover_state.render(&snapshot, &style, visible_rows, cx); mode = view.mode; - view.render_fold_indicators(folds, &style, view.gutter_hovered, cx) + view.render_fold_indicators( + folds, + &style, + view.gutter_hovered, + line_height, + gutter_margin, + cx, + ) }); if let Some((_, context_menu)) = context_menu.as_mut() { diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 44379299ff..06122b9dda 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -643,6 +643,9 @@ pub struct CodeActions { pub struct Folds { pub indicator: Interactive, pub fold_background: Color, + pub icon_width: f32, + pub folded_icon: String, + pub foldable_icon: String, } #[derive(Clone, Deserialize, Default)] diff --git a/styles/src/styleTree/editor.ts b/styles/src/styleTree/editor.ts index 14090d39e9..c8334d1cc0 100644 --- a/styles/src/styleTree/editor.ts +++ b/styles/src/styleTree/editor.ts @@ -60,6 +60,9 @@ export default function editor(colorScheme: ColorScheme) { verticalScale: 0.55, }, folds: { + iconWidth: 8, + foldedIcon: "icons/chevron_right_8.svg", + foldableIcon: "icons/chevron_down_8.svg", indicator: { color: foreground(layer, "variant"),