perf: speed up large markdown rendering

This commit is contained in:
2026-11-06 17:18:11 +07:00
parent 310cad32be
commit e524c1a305
3 changed files with 124 additions and 39 deletions
+13 -6
View File
@@ -7,7 +7,7 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, Context, Div, ElementId, FontStyle, FontWeight, HighlightStyle,
InteractiveElement as _, InteractiveText, IntoElement, ListAlignment, ListState,
InteractiveElement as _, InteractiveText, IntoElement, ListAlignment, ListOffset, ListState,
ParentElement as _, Pixels, Render, SharedString, StatefulInteractiveElement as _,
StrikethroughStyle, Styled as _, StyledText, UnderlineStyle, Window, div, list, px, relative,
};
@@ -190,7 +190,7 @@ impl MarkdownViewState {
source,
blocks,
highlight_code: true,
handle: ListState::new(count, ListAlignment::Top, px(400.)).measure_all(),
handle: ListState::new(count, ListAlignment::Top, px(400.)),
a11y_label: None,
}
}
@@ -207,7 +207,11 @@ impl MarkdownViewState {
where
S: Into<SharedString>,
{
self.source = source.into();
let source = source.into();
if self.source == source {
return;
}
self.source = source;
self.reparse();
cx.notify();
}
@@ -233,10 +237,13 @@ impl MarkdownViewState {
self.highlight_code
}
/// Scrolls `block` into view.
/// Scrolls `block` to the top of the view.
pub fn scroll_to_block(&self, block: usize) {
self.handle
.scroll_to_reveal_item(block.min(self.blocks.len().saturating_sub(1)));
let item_ix = block.min(self.blocks.len().saturating_sub(1));
self.handle.scroll_to(ListOffset {
item_ix,
offset_in_item: px(0.),
});
}
/// Overrides the accessibility label of the view.