diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 3e740f7b75deb7c9c3c0b8be1923cb0739306e6a..80676138e2de280e359ea754be59c3a460183804 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -193,9 +193,9 @@ impl DisplayMap { self.text_highlights.remove(&Some(type_id)) } - pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext) { + pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext) -> bool { self.wrap_map - .update(cx, |map, cx| map.set_font(font_id, font_size, cx)); + .update(cx, |map, cx| map.set_font(font_id, font_size, cx)) } pub fn set_wrap_width(&self, width: Option, cx: &mut ModelContext) -> bool { diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 0e88d87bd77b06ff3a4ab8bfb49c7f0c1aa2433e..33cd5438e3ae9bceab63566afb7851b8617aca5d 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -121,10 +121,18 @@ impl WrapMap { (self.snapshot.clone(), mem::take(&mut self.edits_since_sync)) } - pub fn set_font(&mut self, font_id: FontId, font_size: f32, cx: &mut ModelContext) { + pub fn set_font( + &mut self, + font_id: FontId, + font_size: f32, + cx: &mut ModelContext, + ) -> bool { if (font_id, font_size) != self.font { self.font = (font_id, font_size); - self.rewrap(cx) + self.rewrap(cx); + true + } else { + false } } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b339bbc8e417afeb69f95244c20a62f023467061..6ec885288818a334a03c0f2a9b5490320ffe9014 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5688,9 +5688,22 @@ impl Entity for Editor { impl View for Editor { fn render(&mut self, cx: &mut RenderContext) -> ElementBox { let style = self.style(cx); - self.display_map.update(cx, |map, cx| { + let font_changed = self.display_map.update(cx, |map, cx| { map.set_font(style.text.font_id, style.text.font_size, cx) }); + + // If the + if font_changed { + let handle = self.handle.clone(); + cx.defer(move |cx| { + if let Some(editor) = handle.upgrade(cx) { + editor.update(cx, |editor, cx| { + hide_hover(editor, cx); + }) + } + }); + } + EditorElement::new(self.handle.clone(), style.clone(), self.cursor_shape).boxed() } diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 47ae6a5609ce170ccd75c238a8b839a39deefeaf..c883ff2e4585476e0ed81588905aa09e12a028a4 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -62,11 +62,10 @@ pub fn hide_hover(editor: &mut Editor, cx: &mut ViewContext) -> bool { did_hide = true; cx.notify(); } + editor.hover_state.task = None; editor.clear_background_highlights::(cx); - editor.hover_state.task = None; - did_hide } @@ -86,16 +85,6 @@ fn show_hover( let snapshot = editor.snapshot(cx); let multibuffer_offset = point.to_offset(&snapshot.display_snapshot, Bias::Left); - if let Some(range) = &editor.hover_state.symbol_range { - if range - .to_offset(&snapshot.buffer_snapshot) - .contains(&multibuffer_offset) - { - // Hover triggered from same location as last time. Don't show again. - return; - } - } - let (buffer, buffer_position) = if let Some(output) = editor .buffer .read(cx) @@ -137,6 +126,18 @@ fn show_hover( .unwrap_or(true) // Hover was visible recently enough && !ignore_timeout; // Hover triggered from keyboard + if should_delay { + if let Some(range) = &editor.hover_state.symbol_range { + if range + .to_offset(&snapshot.buffer_snapshot) + .contains(&multibuffer_offset) + { + // Hover triggered from same location as last time. Don't show again. + return; + } + } + } + // Get input anchor let anchor = snapshot .buffer_snapshot @@ -206,6 +207,10 @@ fn show_hover( cx.notify(); } + + if this.hover_state.popover.is_none() { + this.hover_state.symbol_range = None; + } }); } Ok::<_, anyhow::Error>(())