mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 10:29:35 +03:00
Render editor fold indicators using Disclosure
s (#13008)
This PR updates the spots where we render the fold indicators in editors to use the `Disclosure` component instead of re-implementing similar UI. This makes this UI more consistent across Zed. Release Notes: - N/A
This commit is contained in:
parent
af8e7af265
commit
1a40e98413
@ -54,8 +54,8 @@ use std::{
|
||||
};
|
||||
use telemetry_events::AssistantKind;
|
||||
use ui::{
|
||||
popover_menu, prelude::*, ButtonLike, ContextMenu, ElevationIndex, KeyBinding, ListItem,
|
||||
ListItemSpacing, PopoverMenuHandle, Tab, TabBar, Tooltip,
|
||||
popover_menu, prelude::*, ButtonLike, ContextMenu, Disclosure, ElevationIndex, KeyBinding,
|
||||
ListItem, ListItemSpacing, PopoverMenuHandle, Tab, TabBar, Tooltip,
|
||||
};
|
||||
use util::{paths::CONTEXTS_DIR, post_inc, ResultExt, TryFutureExt};
|
||||
use uuid::Uuid;
|
||||
@ -3132,16 +3132,9 @@ fn render_slash_command_output_toggle(
|
||||
fold: ToggleFold,
|
||||
_cx: &mut WindowContext,
|
||||
) -> AnyElement {
|
||||
IconButton::new(
|
||||
("slash-command-output-fold-indicator", row.0),
|
||||
ui::IconName::ChevronDown,
|
||||
)
|
||||
.on_click(move |_e, cx| fold(!is_folded, cx))
|
||||
.icon_color(ui::Color::Muted)
|
||||
.icon_size(ui::IconSize::Small)
|
||||
Disclosure::new(("slash-command-output-fold-indicator", row.0), !is_folded)
|
||||
.selected(is_folded)
|
||||
.selected_icon(ui::IconName::ChevronRight)
|
||||
.size(ui::ButtonSize::None)
|
||||
.on_click(move |_e, cx| fold(!is_folded, cx))
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
|
@ -138,8 +138,8 @@ use theme::{
|
||||
ThemeColors, ThemeSettings,
|
||||
};
|
||||
use ui::{
|
||||
h_flex, prelude::*, ButtonSize, ButtonStyle, IconButton, IconName, IconSize, ListItem, Popover,
|
||||
Tooltip,
|
||||
h_flex, prelude::*, ButtonSize, ButtonStyle, Disclosure, IconButton, IconName, IconSize,
|
||||
ListItem, Popover, Tooltip,
|
||||
};
|
||||
use util::{defer, maybe, post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||
use workspace::item::{ItemHandle, PreviewTabsSettings};
|
||||
@ -11752,10 +11752,8 @@ impl EditorSnapshot {
|
||||
|| (self.starts_indent(buffer_row) && (row_contains_cursor || self.gutter_hovered))
|
||||
{
|
||||
Some(
|
||||
IconButton::new(
|
||||
("indent-fold-indicator", buffer_row.0),
|
||||
ui::IconName::ChevronDown,
|
||||
)
|
||||
Disclosure::new(("indent-fold-indicator", buffer_row.0), !folded)
|
||||
.selected(folded)
|
||||
.on_click(cx.listener_for(&editor, move |this, _e, cx| {
|
||||
if folded {
|
||||
this.unfold_at(&UnfoldAt { buffer_row }, cx);
|
||||
@ -11763,11 +11761,6 @@ impl EditorSnapshot {
|
||||
this.fold_at(&FoldAt { buffer_row }, cx);
|
||||
}
|
||||
}))
|
||||
.icon_color(ui::Color::Muted)
|
||||
.icon_size(ui::IconSize::Small)
|
||||
.selected(folded)
|
||||
.selected_icon(ui::IconName::ChevronRight)
|
||||
.size(ui::ButtonSize::None)
|
||||
.into_any_element(),
|
||||
)
|
||||
} else {
|
||||
|
@ -8,6 +8,7 @@ use crate::{prelude::*, Color, IconButton, IconButtonShape, IconName, IconSize};
|
||||
pub struct Disclosure {
|
||||
id: ElementId,
|
||||
is_open: bool,
|
||||
selected: bool,
|
||||
on_toggle: Option<Arc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
@ -16,6 +17,7 @@ impl Disclosure {
|
||||
Self {
|
||||
id: id.into(),
|
||||
is_open,
|
||||
selected: false,
|
||||
on_toggle: None,
|
||||
}
|
||||
}
|
||||
@ -29,6 +31,20 @@ impl Disclosure {
|
||||
}
|
||||
}
|
||||
|
||||
impl Selectable for Disclosure {
|
||||
fn selected(mut self, selected: bool) -> Self {
|
||||
self.selected = selected;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Clickable for Disclosure {
|
||||
fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
|
||||
self.on_toggle = Some(Arc::new(handler));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Disclosure {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
IconButton::new(
|
||||
@ -41,6 +57,7 @@ impl RenderOnce for Disclosure {
|
||||
.shape(IconButtonShape::Square)
|
||||
.icon_color(Color::Muted)
|
||||
.icon_size(IconSize::Small)
|
||||
.selected(self.selected)
|
||||
.when_some(self.on_toggle, move |this, on_toggle| {
|
||||
this.on_click(move |event, cx| on_toggle(event, cx))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user