Improve toggle UI, fix inlays update speed

This commit is contained in:
Kirill Bulatov 2023-08-10 12:28:17 +03:00
parent 6a326c1bd8
commit 0b93e490a5
3 changed files with 12 additions and 10 deletions

View file

@ -1240,7 +1240,7 @@ enum GotoDefinitionKind {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum InlayRefreshReason { enum InlayRefreshReason {
Toggled(bool), Toggle(bool),
SettingsChange(InlayHintSettings), SettingsChange(InlayHintSettings),
NewLinesShown, NewLinesShown,
BufferEdited(HashSet<Arc<Language>>), BufferEdited(HashSet<Arc<Language>>),
@ -2673,11 +2673,10 @@ impl Editor {
} }
pub fn toggle_inlays(&mut self, _: &ToggleInlays, cx: &mut ViewContext<Self>) { pub fn toggle_inlays(&mut self, _: &ToggleInlays, cx: &mut ViewContext<Self>) {
self.inlay_hint_cache.enabled = !self.inlay_hint_cache.enabled;
self.refresh_inlays( self.refresh_inlays(
InlayRefreshReason::Toggled(self.inlay_hint_cache.enabled), InlayRefreshReason::Toggle(!self.inlay_hint_cache.enabled),
cx, cx,
) );
} }
pub fn inlays_enabled(&self) -> bool { pub fn inlays_enabled(&self) -> bool {
@ -2690,7 +2689,8 @@ impl Editor {
} }
let (invalidate_cache, required_languages) = match reason { let (invalidate_cache, required_languages) = match reason {
InlayRefreshReason::Toggled(enabled) => { InlayRefreshReason::Toggle(enabled) => {
self.inlay_hint_cache.enabled = enabled;
if enabled { if enabled {
(InvalidationStrategy::RefreshRequested, None) (InvalidationStrategy::RefreshRequested, None)
} else { } else {
@ -2805,6 +2805,7 @@ impl Editor {
self.display_map.update(cx, |display_map, cx| { self.display_map.update(cx, |display_map, cx| {
display_map.splice_inlays(to_remove, to_insert, cx); display_map.splice_inlays(to_remove, to_insert, cx);
}); });
cx.notify();
} }
fn trigger_on_type_formatting( fn trigger_on_type_formatting(

View file

@ -45,10 +45,7 @@ impl View for QuickActionBar {
0, 0,
"icons/hamburger_15.svg", "icons/hamburger_15.svg",
inlays_enabled, inlays_enabled,
( ("Inlays".to_string(), Some(Box::new(editor::ToggleInlays))),
"Toggle inlays".to_string(),
Some(Box::new(editor::ToggleInlays)),
),
cx, cx,
|this, cx| { |this, cx| {
if let Some(editor) = this.active_editor() { if let Some(editor) = this.active_editor() {
@ -78,7 +75,8 @@ impl View for QuickActionBar {
"icons/magnifying_glass_12.svg", "icons/magnifying_glass_12.svg",
search_bar_shown, search_bar_shown,
( (
"Toggle buffer search".to_string(), "Buffer search".to_string(),
// TODO kb no keybinding is shown for search + toggle inlays does not update icon color
Some(Box::new(search_action.clone())), Some(Box::new(search_action.clone())),
), ),
cx, cx,
@ -132,6 +130,8 @@ fn render_quick_action_bar_button<
.constrained() .constrained()
.with_width(style.button_width) .with_width(style.button_width)
.with_height(style.button_width) .with_height(style.button_width)
.contained()
.with_style(style.container)
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, pane, cx| on_click(pane, cx)) .on_click(MouseButton::Left, move |_, pane, cx| on_click(pane, cx))

View file

@ -151,6 +151,7 @@ export default function workspace(): any {
}, },
}), }),
toggleable_tool: toggleable_icon_button(theme, { toggleable_tool: toggleable_icon_button(theme, {
margin: { left: 8 },
active_color: "accent", active_color: "accent",
}), }),
padding: { left: 8, right: 8, top: 4, bottom: 4 }, padding: { left: 8, right: 8, top: 4, bottom: 4 },