agent: Optimize render_markdown_block function (#28487)

Bennet Bo Fenner and Agus created

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

Closes #ISSUE

Release Notes:

- N/A

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

Change summary

crates/agent/src/active_thread.rs | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

Detailed changes

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()