From 53d1edb2a6957482f32c440d7c7fef92b91e4acb Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 15:14:18 +0000 Subject: [PATCH] Fix the panic when trying to interact with editor-like not-editors (#49608) (cherry-pick to stable) (#49611) Cherry-pick of #49608 to stable ---- For example, LSP log view is not a real editor but can pretend to be one. Release Notes: - Fixed dev highlights view panicking when interacting with editor-like not-editors Co-authored-by: Kirill Bulatov --- .../src/highlights_tree_view.rs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/language_tools/src/highlights_tree_view.rs b/crates/language_tools/src/highlights_tree_view.rs index 1c2593d93750e9b81284f69f9d307b959170be82..0a046faacde1f6e30dd4c5058e033bac820c0b77 100644 --- a/crates/language_tools/src/highlights_tree_view.rs +++ b/crates/language_tools/src/highlights_tree_view.rs @@ -189,8 +189,9 @@ impl HighlightsTreeView { ) { let Some(editor) = active_item .filter(|item| item.item_id() != cx.entity_id()) - .and_then(|item| item.act_as::(cx)) + .and_then(|item| item.downcast::()) else { + self.clear(cx); return; }; @@ -214,20 +215,27 @@ impl HighlightsTreeView { .as_ref() .is_some_and(|state| state.editor.entity_id() == *item_id) { - self.editor = None; - self.cached_entries.clear(); - self.display_items.clear(); - cx.notify(); + self.clear(cx); } } + fn clear(&mut self, cx: &mut Context) { + self.cached_entries.clear(); + self.display_items.clear(); + self.selected_item_ix = None; + self.hovered_item_ix = None; + if let Some(state) = self.editor.take() { + Self::clear_editor_highlights(&state.editor, cx); + } + cx.notify(); + } + fn set_editor(&mut self, editor: Entity, window: &mut Window, cx: &mut Context) { if let Some(state) = &self.editor { if state.editor == editor { return; } - let key = HighlightKey::HighlightsTreeView(editor.entity_id().as_u64() as usize); - editor.update(cx, |editor, cx| editor.clear_background_highlights(key, cx)); + Self::clear_editor_highlights(&state.editor, cx); } let subscription = @@ -248,9 +256,7 @@ impl HighlightsTreeView { fn refresh_highlights(&mut self, _window: &mut Window, cx: &mut Context) { let Some(editor_state) = self.editor.as_ref() else { - self.cached_entries.clear(); - self.display_items.clear(); - cx.notify(); + self.clear(cx); return; };