Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions crates/language_tools/src/highlights_tree_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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 =
Expand All @@ -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;
};

Expand Down