From ad05ba59256a67f429b71a8aba2cd92ed2cafac7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 12 Mar 2023 12:53:50 +0100 Subject: Spans in math --- library/src/math/ctx.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'library/src/math/ctx.rs') diff --git a/library/src/math/ctx.rs b/library/src/math/ctx.rs index 991d582c..bd44546d 100644 --- a/library/src/math/ctx.rs +++ b/library/src/math/ctx.rs @@ -124,13 +124,15 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { .into_frame()) } - pub fn layout_text(&mut self, text: &str) -> SourceResult<()> { + pub fn layout_text(&mut self, node: &TextNode) -> SourceResult<()> { + let text = node.text(); + let span = node.span(); let mut chars = text.chars(); if let Some(glyph) = chars .next() .filter(|_| chars.next().is_none()) .map(|c| self.style.styled_char(c)) - .and_then(|c| GlyphFragment::try_new(self, c)) + .and_then(|c| GlyphFragment::try_new(self, c, span)) { // A single letter that is available in the math font. if self.style.size == MathSize::Display @@ -146,7 +148,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { let mut fragments = vec![]; for c in text.chars() { let c = self.style.styled_char(c); - fragments.push(GlyphFragment::new(self, c).into()); + fragments.push(GlyphFragment::new(self, c, span).into()); } let frame = MathRow::new(fragments).to_frame(self); self.push(FrameFragment::new(self, frame)); @@ -158,7 +160,7 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> { style = style.with_italic(false); } let text: EcoString = text.chars().map(|c| style.styled_char(c)).collect(); - let frame = self.layout_content(&TextNode::packed(text))?; + let frame = self.layout_content(&TextNode::packed(text).spanned(span))?; self.push( FrameFragment::new(self, frame) .with_class(MathClass::Alphabetic) -- cgit v1.2.3