Repaint inlays icon on inlays cache disabling/enabling

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Kirill Bulatov 2023-08-10 13:30:12 +03:00
parent 0b93e490a5
commit 0f650acc23
3 changed files with 25 additions and 6 deletions

View file

@ -24,7 +24,7 @@ pub struct InlayHintCache {
hints: HashMap<ExcerptId, Arc<RwLock<CachedExcerptHints>>>, hints: HashMap<ExcerptId, Arc<RwLock<CachedExcerptHints>>>,
allowed_hint_kinds: HashSet<Option<InlayHintKind>>, allowed_hint_kinds: HashSet<Option<InlayHintKind>>,
version: usize, version: usize,
enabled: bool, pub(super) enabled: bool,
update_tasks: HashMap<ExcerptId, TasksForRanges>, update_tasks: HashMap<ExcerptId, TasksForRanges>,
} }

View file

@ -88,8 +88,12 @@ impl Binding {
action: &dyn Action, action: &dyn Action,
contexts: &[KeymapContext], contexts: &[KeymapContext],
) -> Option<SmallVec<[Keystroke; 2]>> { ) -> Option<SmallVec<[Keystroke; 2]>> {
if self.action.eq(action) && self.match_context(contexts) { if self.action.eq(action) {
Some(self.keystrokes.clone()) if self.match_context(contexts) {
Some(self.keystrokes.clone())
} else {
None
}
} else { } else {
None None
} }

View file

@ -2,7 +2,7 @@ use editor::Editor;
use gpui::{ use gpui::{
elements::{Empty, Flex, MouseEventHandler, ParentElement, Svg}, elements::{Empty, Flex, MouseEventHandler, ParentElement, Svg},
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
Action, AnyElement, Element, Entity, EventContext, View, ViewContext, ViewHandle, Action, AnyElement, Element, Entity, EventContext, Subscription, View, ViewContext, ViewHandle,
}; };
use search::{buffer_search, BufferSearchBar}; use search::{buffer_search, BufferSearchBar};
@ -11,6 +11,7 @@ use workspace::{item::ItemHandle, Pane, ToolbarItemLocation, ToolbarItemView};
pub struct QuickActionBar { pub struct QuickActionBar {
pane: ViewHandle<Pane>, pane: ViewHandle<Pane>,
active_item: Option<Box<dyn ItemHandle>>, active_item: Option<Box<dyn ItemHandle>>,
_inlays_enabled_subscription: Option<Subscription>,
} }
impl QuickActionBar { impl QuickActionBar {
@ -18,6 +19,7 @@ impl QuickActionBar {
Self { Self {
pane, pane,
active_item: None, active_item: None,
_inlays_enabled_subscription: None,
} }
} }
@ -76,7 +78,6 @@ impl View for QuickActionBar {
search_bar_shown, search_bar_shown,
( (
"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,
@ -143,11 +144,25 @@ impl ToolbarItemView for QuickActionBar {
fn set_active_pane_item( fn set_active_pane_item(
&mut self, &mut self,
active_pane_item: Option<&dyn ItemHandle>, active_pane_item: Option<&dyn ItemHandle>,
_: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> ToolbarItemLocation { ) -> ToolbarItemLocation {
match active_pane_item { match active_pane_item {
Some(active_item) => { Some(active_item) => {
self.active_item = Some(active_item.boxed_clone()); self.active_item = Some(active_item.boxed_clone());
self._inlays_enabled_subscription.take();
if let Some(editor) = active_item.downcast::<Editor>() {
let mut inlays_enabled = editor.read(cx).inlays_enabled();
self._inlays_enabled_subscription =
Some(cx.observe(&editor, move |_, editor, cx| {
let new_inlays_enabled = editor.read(cx).inlays_enabled();
if inlays_enabled != new_inlays_enabled {
inlays_enabled = new_inlays_enabled;
cx.notify();
}
}));
}
ToolbarItemLocation::PrimaryRight { flex: None } ToolbarItemLocation::PrimaryRight { flex: None }
} }
None => { None => {