diff --git a/crates/ui/src/text/markdown.rs b/crates/ui/src/text/markdown.rs index 56d85ff3..23a4b9ca 100644 --- a/crates/ui/src/text/markdown.rs +++ b/crates/ui/src/text/markdown.rs @@ -1,3 +1,5 @@ +use std::time::Instant; + use gpui::{ div, prelude::FluentBuilder as _, AnyElement, App, Element, ElementId, IntoElement, ParentElement, SharedString, Styled, Window, @@ -57,6 +59,7 @@ pub struct MarkdownState { raw: SharedString, root: Option>, style: TextViewStyle, + _last_parsed: Option, } impl MarkdownState { @@ -67,8 +70,18 @@ impl MarkdownState { return; } + if let Some(last_parsed) = self._last_parsed { + if last_parsed.elapsed().as_millis() < 500 { + return; + } + } + self.raw = new_text; + // NOTE: About 100ms + // let measure = crate::Measure::new("parse_markdown"); self.root = Some(parse_markdown(&self.raw, &style, cx)); + // measure.end(); + self._last_parsed = Some(Instant::now()); self.style = style.clone(); } }