Adjusted code-folding behavior
This commit is contained in:
parent
e0f553c0f5
commit
9b8adecf05
4 changed files with 66 additions and 38 deletions
|
@ -2698,52 +2698,67 @@ impl Editor {
|
||||||
&self,
|
&self,
|
||||||
fold_data: Option<Vec<(u32, FoldStatus)>>,
|
fold_data: Option<Vec<(u32, FoldStatus)>>,
|
||||||
style: &EditorStyle,
|
style: &EditorStyle,
|
||||||
_gutter_hovered: bool,
|
gutter_hovered: bool,
|
||||||
|
line_height: f32,
|
||||||
|
gutter_margin: f32,
|
||||||
cx: &mut RenderContext<Self>,
|
cx: &mut RenderContext<Self>,
|
||||||
) -> Option<Vec<(u32, ElementBox)>> {
|
) -> Option<Vec<(u32, ElementBox)>> {
|
||||||
enum FoldIndicators {}
|
enum FoldIndicators {}
|
||||||
|
|
||||||
|
let style = style.folds.clone();
|
||||||
|
|
||||||
fold_data.map(|fold_data| {
|
fold_data.map(|fold_data| {
|
||||||
fold_data
|
fold_data
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.map(|(fold_location, fold_status)| {
|
.filter_map(|(fold_location, fold_status)| {
|
||||||
(
|
(gutter_hovered || fold_status == FoldStatus::Folded).then(|| {
|
||||||
fold_location,
|
(
|
||||||
MouseEventHandler::<FoldIndicators>::new(
|
fold_location,
|
||||||
fold_location as usize,
|
MouseEventHandler::<FoldIndicators>::new(
|
||||||
cx,
|
fold_location as usize,
|
||||||
|mouse_state, _| -> ElementBox {
|
cx,
|
||||||
Svg::new(match fold_status {
|
|mouse_state, _| -> ElementBox {
|
||||||
FoldStatus::Folded => "icons/chevron_right_8.svg",
|
Svg::new(match fold_status {
|
||||||
FoldStatus::Foldable => "icons/chevron_down_8.svg",
|
FoldStatus::Folded => style.folded_icon.clone(),
|
||||||
})
|
FoldStatus::Foldable => style.foldable_icon.clone(),
|
||||||
.with_color(
|
})
|
||||||
style
|
.with_color(
|
||||||
.folds
|
style
|
||||||
.indicator
|
.indicator
|
||||||
.style_for(mouse_state, fold_status == FoldStatus::Folded)
|
.style_for(
|
||||||
.color,
|
mouse_state,
|
||||||
)
|
fold_status == FoldStatus::Folded,
|
||||||
.boxed()
|
)
|
||||||
},
|
.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()
|
.collect()
|
||||||
})
|
})
|
||||||
|
|
|
@ -1829,7 +1829,14 @@ impl Element for EditorElement {
|
||||||
hover = view.hover_state.render(&snapshot, &style, visible_rows, cx);
|
hover = view.hover_state.render(&snapshot, &style, visible_rows, cx);
|
||||||
mode = view.mode;
|
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() {
|
if let Some((_, context_menu)) = context_menu.as_mut() {
|
||||||
|
|
|
@ -643,6 +643,9 @@ pub struct CodeActions {
|
||||||
pub struct Folds {
|
pub struct Folds {
|
||||||
pub indicator: Interactive<Indicator>,
|
pub indicator: Interactive<Indicator>,
|
||||||
pub fold_background: Color,
|
pub fold_background: Color,
|
||||||
|
pub icon_width: f32,
|
||||||
|
pub folded_icon: String,
|
||||||
|
pub foldable_icon: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
|
|
|
@ -60,6 +60,9 @@ export default function editor(colorScheme: ColorScheme) {
|
||||||
verticalScale: 0.55,
|
verticalScale: 0.55,
|
||||||
},
|
},
|
||||||
folds: {
|
folds: {
|
||||||
|
iconWidth: 8,
|
||||||
|
foldedIcon: "icons/chevron_right_8.svg",
|
||||||
|
foldableIcon: "icons/chevron_down_8.svg",
|
||||||
indicator: {
|
indicator: {
|
||||||
color: foreground(layer, "variant"),
|
color: foreground(layer, "variant"),
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue