markdown: Add debounce 500ms to update markdown to avoid render slow. (#953)
Ref #933
This commit is contained in:
parent
e29b51cc83
commit
1032881103
1 changed files with 13 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, AnyElement, App, Element, ElementId, IntoElement,
|
div, prelude::FluentBuilder as _, AnyElement, App, Element, ElementId, IntoElement,
|
||||||
ParentElement, SharedString, Styled, Window,
|
ParentElement, SharedString, Styled, Window,
|
||||||
|
|
@ -57,6 +59,7 @@ pub struct MarkdownState {
|
||||||
raw: SharedString,
|
raw: SharedString,
|
||||||
root: Option<Result<element::Node, SharedString>>,
|
root: Option<Result<element::Node, SharedString>>,
|
||||||
style: TextViewStyle,
|
style: TextViewStyle,
|
||||||
|
_last_parsed: Option<Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MarkdownState {
|
impl MarkdownState {
|
||||||
|
|
@ -67,8 +70,18 @@ impl MarkdownState {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(last_parsed) = self._last_parsed {
|
||||||
|
if last_parsed.elapsed().as_millis() < 500 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.raw = new_text;
|
self.raw = new_text;
|
||||||
|
// NOTE: About 100ms
|
||||||
|
// let measure = crate::Measure::new("parse_markdown");
|
||||||
self.root = Some(parse_markdown(&self.raw, &style, cx));
|
self.root = Some(parse_markdown(&self.raw, &style, cx));
|
||||||
|
// measure.end();
|
||||||
|
self._last_parsed = Some(Instant::now());
|
||||||
self.style = style.clone();
|
self.style = style.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue