From 55760295d9022a66f4173e6637a7b7655392a9e8 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Wed, 9 Apr 2025 22:29:47 -0600 Subject: [PATCH] agent: Optimize render_markdown_block function (#28487) Co-Authored-by: Agus Closes #ISSUE Release Notes: - N/A Co-authored-by: Agus --- crates/agent/src/active_thread.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/agent/src/active_thread.rs b/crates/agent/src/active_thread.rs index fcc119743ae48e4e940fa9c6daaf9b6e63194a98..6c1b45f3e25480052a683b73dee7eba73f05fc7b 100644 --- a/crates/agent/src/active_thread.rs +++ b/crates/agent/src/active_thread.rs @@ -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()