Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix the panic when trying to interact with editor-like not-editors (#49608)
Kirill Bulatovd8b3f476a5fa
diff --git a/crates/language_tools/src/highlights_tree_view.rs b/crates/language_tools/src/highlights_tree_view.rsindex fe09a3f3849..e3e6dccf9b7 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::<Editor>(cx))+ .and_then(|item| item.downcast::<Editor>())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>) {+ 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<Editor>, window: &mut Window, cx: &mut Context<Self>) {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<Self>) {let Some(editor_state) = self.editor.as_ref() else {- self.cached_entries.clear();- self.display_items.clear();- cx.notify();+ self.clear(cx);return;};