diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 2f96b3ef4246c187d406401a60bdaae540cbaa4d..b29708aac9909cb5f25c48513c505f6b7a25be26 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -884,13 +884,21 @@ impl EditorElement { SharedString::from(character.to_string()) }; let len = text.len(); + + let font = cursor_row_layout + .font_id_for_index(cursor_column) + .and_then(|cursor_font_id| { + cx.text_system().get_font_for_id(cursor_font_id) + }) + .unwrap_or(self.style.text.font()); + cx.text_system() .shape_line( text, cursor_row_layout.font_size, &[TextRun { len, - font: self.style.text.font(), + font: font, color: self.style.background, background_color: None, strikethrough: None, diff --git a/crates/gpui/src/text_system.rs b/crates/gpui/src/text_system.rs index 034d15ae343f9bfa7d259050df3c17d616cc0a18..f0c8cfafe3422a43f61f590e3c54c8252611a87b 100644 --- a/crates/gpui/src/text_system.rs +++ b/crates/gpui/src/text_system.rs @@ -117,6 +117,17 @@ impl TextSystem { } } + /// Get the Font for the Font Id. + pub fn get_font_for_id(&self, id: FontId) -> Option { + let lock = self.font_ids_by_font.read(); + lock.iter() + .filter_map(|(font, result)| match result { + Ok(font_id) if *font_id == id => Some(font.clone()), + _ => None, + }) + .next() + } + /// Resolves the specified font, falling back to the default font stack if /// the font fails to load. /// diff --git a/crates/gpui/src/text_system/line_layout.rs b/crates/gpui/src/text_system/line_layout.rs index 877d1d48d4d3b7fb06ce6e13ade5d75fe7742c7d..c98e304c5f5c0f7833dc3a34d5b34f50709bf0b4 100644 --- a/crates/gpui/src/text_system/line_layout.rs +++ b/crates/gpui/src/text_system/line_layout.rs @@ -103,6 +103,18 @@ impl LineLayout { self.width } + /// The corresponding Font at the given index + pub fn font_id_for_index(&self, index: usize) -> Option { + for run in &self.runs { + for glyph in &run.glyphs { + if glyph.index >= index { + return Some(run.font_id); + } + } + } + None + } + fn compute_wrap_boundaries( &self, text: &str,