Make chevrons and lightning bolt interactive
This commit is contained in:
parent
89b93d4f6f
commit
37a2ef9d41
4 changed files with 47 additions and 18 deletions
|
@ -2669,14 +2669,15 @@ impl Editor {
|
||||||
pub fn render_code_actions_indicator(
|
pub fn render_code_actions_indicator(
|
||||||
&self,
|
&self,
|
||||||
style: &EditorStyle,
|
style: &EditorStyle,
|
||||||
|
active: bool,
|
||||||
cx: &mut RenderContext<Self>,
|
cx: &mut RenderContext<Self>,
|
||||||
) -> Option<ElementBox> {
|
) -> Option<ElementBox> {
|
||||||
if self.available_code_actions.is_some() {
|
if self.available_code_actions.is_some() {
|
||||||
enum CodeActions {}
|
enum CodeActions {}
|
||||||
Some(
|
Some(
|
||||||
MouseEventHandler::<CodeActions>::new(0, cx, |_, _| {
|
MouseEventHandler::<CodeActions>::new(0, cx, |state, _| {
|
||||||
Svg::new("icons/bolt_8.svg")
|
Svg::new("icons/bolt_8.svg")
|
||||||
.with_color(style.code_actions.indicator)
|
.with_color(style.code_actions.indicator.style_for(state, active).color)
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
@ -2697,7 +2698,7 @@ 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,
|
||||||
cx: &mut RenderContext<Self>,
|
cx: &mut RenderContext<Self>,
|
||||||
) -> Option<Vec<(u32, ElementBox)>> {
|
) -> Option<Vec<(u32, ElementBox)>> {
|
||||||
enum FoldIndicators {}
|
enum FoldIndicators {}
|
||||||
|
@ -2712,24 +2713,24 @@ impl Editor {
|
||||||
MouseEventHandler::<FoldIndicators>::new(
|
MouseEventHandler::<FoldIndicators>::new(
|
||||||
fold_location as usize,
|
fold_location as usize,
|
||||||
cx,
|
cx,
|
||||||
|_, _| -> ElementBox {
|
|mouse_state, _| -> ElementBox {
|
||||||
Svg::new(match fold_status {
|
Svg::new(match fold_status {
|
||||||
FoldStatus::Folded => "icons/chevron_right_8.svg",
|
FoldStatus::Folded => "icons/chevron_right_8.svg",
|
||||||
FoldStatus::Foldable => "icons/chevron_down_8.svg",
|
FoldStatus::Foldable => "icons/chevron_down_8.svg",
|
||||||
})
|
})
|
||||||
.with_color(
|
.with_color(
|
||||||
if gutter_hovered || fold_status == FoldStatus::Folded {
|
style
|
||||||
style.folds.indicator
|
.folds
|
||||||
} else {
|
.indicator
|
||||||
style.folds.faded_indicator
|
.style_for(mouse_state, fold_status == FoldStatus::Folded)
|
||||||
},
|
.color,
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.with_padding(Padding::uniform(3.))
|
.with_padding(Padding::uniform(3.))
|
||||||
.on_down(MouseButton::Left, {
|
.on_click(MouseButton::Left, {
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
cx.dispatch_any_action(match fold_status {
|
cx.dispatch_any_action(match fold_status {
|
||||||
FoldStatus::Folded => Box::new(UnfoldAt {
|
FoldStatus::Folded => Box::new(UnfoldAt {
|
||||||
|
|
|
@ -1818,8 +1818,10 @@ impl Element for EditorElement {
|
||||||
view.render_context_menu(newest_selection_head, style.clone(), cx);
|
view.render_context_menu(newest_selection_head, style.clone(), cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let active = matches!(view.context_menu, Some(crate::ContextMenu::CodeActions(_)));
|
||||||
|
|
||||||
code_actions_indicator = view
|
code_actions_indicator = view
|
||||||
.render_code_actions_indicator(&style, cx)
|
.render_code_actions_indicator(&style, active, cx)
|
||||||
.map(|indicator| (newest_selection_head.row(), indicator));
|
.map(|indicator| (newest_selection_head.row(), indicator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -635,18 +635,21 @@ pub struct FieldEditor {
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
pub struct CodeActions {
|
pub struct CodeActions {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub indicator: Color,
|
pub indicator: Interactive<Indicator>,
|
||||||
pub vertical_scale: f32,
|
pub vertical_scale: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
pub struct Folds {
|
pub struct Folds {
|
||||||
#[serde(default)]
|
pub indicator: Interactive<Indicator>,
|
||||||
pub indicator: Color,
|
|
||||||
pub faded_indicator: Color,
|
|
||||||
pub fold_background: Color,
|
pub fold_background: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, Default)]
|
||||||
|
pub struct Indicator {
|
||||||
|
pub color: Color,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default)]
|
#[derive(Clone, Deserialize, Default)]
|
||||||
pub struct DiffStyle {
|
pub struct DiffStyle {
|
||||||
pub inserted: Color,
|
pub inserted: Color,
|
||||||
|
|
|
@ -44,12 +44,35 @@ export default function editor(colorScheme: ColorScheme) {
|
||||||
activeLineBackground: withOpacity(background(layer, "on"), 0.75),
|
activeLineBackground: withOpacity(background(layer, "on"), 0.75),
|
||||||
highlightedLineBackground: background(layer, "on"),
|
highlightedLineBackground: background(layer, "on"),
|
||||||
codeActions: {
|
codeActions: {
|
||||||
indicator: foreground(layer, "variant"),
|
indicator: {
|
||||||
|
color: foreground(layer, "variant"),
|
||||||
|
|
||||||
|
clicked: {
|
||||||
|
color: foreground(layer, "base"),
|
||||||
|
},
|
||||||
|
hover: {
|
||||||
|
color: foreground(layer, "on"),
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
color: foreground(layer, "on"),
|
||||||
|
},
|
||||||
|
},
|
||||||
verticalScale: 0.55,
|
verticalScale: 0.55,
|
||||||
},
|
},
|
||||||
folds: {
|
folds: {
|
||||||
indicator: foreground(layer, "variant"),
|
indicator: {
|
||||||
fadedIndicator: background(layer, "on"),
|
color: foreground(layer, "variant"),
|
||||||
|
|
||||||
|
clicked: {
|
||||||
|
color: foreground(layer, "base"),
|
||||||
|
},
|
||||||
|
hover: {
|
||||||
|
color: foreground(layer, "on"),
|
||||||
|
},
|
||||||
|
active: {
|
||||||
|
color: foreground(layer, "on"),
|
||||||
|
},
|
||||||
|
},
|
||||||
foldBackground: foreground(layer, "variant"),
|
foldBackground: foreground(layer, "variant"),
|
||||||
},
|
},
|
||||||
diff: {
|
diff: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue