Drop active searchable item subscription when changing active item

We were leaking the previous active item's subscription, which meant
that we would receive the `MatchesInvalidated` event as many times as
we changed items.

Co-Authored-By: Thorsten Ball <thorsten@zed.dev>
Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-01-23 18:31:21 +01:00
parent 21e6b09361
commit b151e12890

View file

@ -396,8 +396,8 @@ impl ToolbarItemView for BufferSearchBar {
{
let this = cx.view().downgrade();
searchable_item_handle
.subscribe_to_search_events(
self.active_searchable_item_subscription =
Some(searchable_item_handle.subscribe_to_search_events(
cx,
Box::new(move |search_event, cx| {
if let Some(this) = this.upgrade() {
@ -406,8 +406,7 @@ impl ToolbarItemView for BufferSearchBar {
});
}
}),
)
.detach();
));
self.active_searchable_item = Some(searchable_item_handle);
let _ = self.update_matches(cx);