Avoid re-rendering editor on mouse move

Nathan Sobo and Max Brunsfeld created

Only notify editor when clearing highlights if there were highlights to
begin with.

Co-Authored-By: Max Brunsfeld <max@zed.dev>

Change summary

crates/editor/src/editor.rs | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -5792,8 +5792,11 @@ impl Editor {
         &mut self,
         cx: &mut ViewContext<Self>,
     ) -> Option<(fn(&Theme) -> Color, Vec<Range<Anchor>>)> {
-        cx.notify();
-        self.background_highlights.remove(&TypeId::of::<T>())
+        let highlights = self.background_highlights.remove(&TypeId::of::<T>());
+        if highlights.is_some() {
+            cx.notify();
+        }
+        highlights
     }
 
     #[cfg(feature = "test-support")]
@@ -5907,9 +5910,13 @@ impl Editor {
         &mut self,
         cx: &mut ViewContext<Self>,
     ) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
-        cx.notify();
-        self.display_map
-            .update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()))
+        let highlights = self
+            .display_map
+            .update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
+        if highlights.is_some() {
+            cx.notify();
+        }
+        highlights
     }
 
     fn next_blink_epoch(&mut self) -> usize {