From 5f1eee3c6611aa9c04ed5defb0c4202a9fa2b223 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sat, 4 Jan 2025 01:26:08 -0700 Subject: [PATCH] Fix inlay hints display reverting to settings value on theme change (#22605) Closes #4276 Release Notes: - Fixed inlay hints that have been manually enabled disappearing when theme selector is used. --- crates/editor/src/inlay_hint_cache.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index 9c0d3d1bc288a..739fb98226b77 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>, version: usize, pub(super) enabled: bool, + enabled_in_settings: bool, update_tasks: HashMap, refresh_task: Option>, invalidate_debounce: Option, @@ -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, cx: &mut ViewContext, ) -> ControlFlow> { + 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(()) }