Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix inlay hints display reverting to settings value on theme change (#22605)
Michael Sloan5f1eee3c6611
diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rsindex 9c0d3d1bc28..739fb98226b 100644--- a/crates/editor/src/inlay_hint_cache.rs+++ b/crates/editor/src/inlay_hint_cache.rs@@ -36,6 +36,7 @@ pub struct InlayHintCache {allowed_hint_kinds: HashSet<Option<InlayHintKind>>,version: usize,pub(super) enabled: bool,+ enabled_in_settings: bool,update_tasks: HashMap<ExcerptId, TasksForRanges>,refresh_task: Option<Task<()>>,invalidate_debounce: Option<Duration>,@@ -268,6 +269,7 @@ impl InlayHintCache {Self {allowed_hint_kinds: inlay_hint_settings.enabled_inlay_hint_kinds(),enabled: inlay_hint_settings.enabled,+ enabled_in_settings: inlay_hint_settings.enabled,hints: HashMap::default(),update_tasks: HashMap::default(),refresh_task: None,@@ -288,10 +290,21 @@ impl InlayHintCache {visible_hints: Vec<Inlay>,cx: &mut ViewContext<Editor>,) -> ControlFlow<Option<InlaySplice>> {+ let old_enabled = self.enabled;+ // If the setting for inlay hints has changed, update `enabled`. This condition avoids inlay+ // hint visibility changes when other settings change (such as theme).+ //+ // Another option might be to store whether the user has manually toggled inlay hint+ // visibility, and prefer this. This could lead to confusion as it means inlay hint+ // visibility would not change when updating the setting if they were ever toggled.+ if new_hint_settings.enabled != self.enabled_in_settings {+ self.enabled = new_hint_settings.enabled;+ };+ self.enabled_in_settings = new_hint_settings.enabled;self.invalidate_debounce = debounce_value(new_hint_settings.edit_debounce_ms);self.append_debounce = debounce_value(new_hint_settings.scroll_debounce_ms);let new_allowed_hint_kinds = new_hint_settings.enabled_inlay_hint_kinds();- match (self.enabled, new_hint_settings.enabled) {+ match (old_enabled, self.enabled) {(false, false) => {self.allowed_hint_kinds = new_allowed_hint_kinds;ControlFlow::Break(None)@@ -314,7 +327,6 @@ impl InlayHintCache {}}(true, false) => {- self.enabled = new_hint_settings.enabled;self.allowed_hint_kinds = new_allowed_hint_kinds;if self.hints.is_empty() {ControlFlow::Break(None)@@ -327,7 +339,6 @@ impl InlayHintCache {}}(false, true) => {- self.enabled = new_hint_settings.enabled;self.allowed_hint_kinds = new_allowed_hint_kinds;ControlFlow::Continue(())}