agent: Optimize render_markdown_block function (#28487)

Co-Authored-by: Agus <agus@zed.dev>

Closes #ISSUE

Release Notes:

- N/A

Co-authored-by: Agus <agus@zed.dev>
This commit is contained in:
Bennet Bo Fenner 2025-04-09 22:29:47 -06:00 committed by GitHub
parent 9dfb907f97
commit 55760295d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -467,12 +467,15 @@ fn render_markdown_code_block(
.element_background
.blend(cx.theme().colors().editor_foreground.opacity(0.01));
let line_count = without_fences(&parsed_markdown.source()[codeblock_range.clone()])
.lines()
.count();
const CODE_FENCES_LINE_COUNT: usize = 2;
const MAX_COLLAPSED_LINES: usize = 5;
let line_count = parsed_markdown.source()[codeblock_range.clone()]
.bytes()
.filter(|c| *c == b'\n')
.count()
.saturating_sub(CODE_FENCES_LINE_COUNT - 1);
let codeblock_header = h_flex()
.group("codeblock_header")
.p_1()