Fix TUI Markdown line breaks before inline code (#64400)

## Why

When a paragraph starts with inline code after a heading in a list
item, the renderer can append the code to the heading's line.

## What changed

Honor pending line breaks before rendering inline code using the same
line-start logic as links. Table cells keep their inline layout.

## Testing

Extend the rendering and transcript copy snapshots to cover a list
item with a heading followed by inline code. The copy cases cover
both the full item and a selection within the code span.

GitOrigin-RevId: bcc480cb9aa2cbf7ab0738f1ec3667677445987a
This commit is contained in:
Felipe Coury
2026-11-28 00:05:22 +00:00
committed by copyberry
parent d96685f508
commit 246e5bae5a
6 changed files with 28 additions and 10 deletions
+10 -8
View File
@@ -1052,6 +1052,14 @@ impl<'a, 'policy> Writer<'a, 'policy> {
self.needs_newline = false;
}
/// Begin an inline run at the list marker or after the preceding block.
fn start_pending_inline_line(&mut self) {
if (self.pending_marker_line || self.needs_newline) && !self.in_table_cell() {
self.push_line(Line::default());
self.needs_newline = false;
}
}
fn code(&mut self, code: CowStr<'a>) {
if self.buffer_link_label(&code) {
self.push_local_link_label_span(Span::from(code.into_string()).style(self.styles.code));
@@ -1063,10 +1071,7 @@ impl<'a, 'policy> Writer<'a, 'policy> {
return;
}
if self.pending_marker_line {
self.push_line(Line::default());
self.pending_marker_line = false;
}
self.start_pending_inline_line();
let span = Span::from(code.into_string()).style(self.styles.code);
self.push_span(span);
}
@@ -2385,10 +2390,7 @@ impl<'a, 'policy> Writer<'a, 'policy> {
}
fn push_link(&mut self, dest_url: String, source: usize) {
if (self.pending_marker_line || self.needs_newline) && !self.in_table_cell() {
self.push_line(Line::default());
self.needs_newline = false;
}
self.start_pending_inline_line();
let style_label = (self.is_hidden_link_destination)(&dest_url);
if style_label {
self.push_inline_style(self.styles.link);
@@ -1060,6 +1060,10 @@ second](guide.md)
[Map](guide.md#L2-L4) details
- # Explicit
[`Map`](./guide.md#L2-L4) details
- # Inline
`Map` details
- # Plain
Map details
- # Source
[source.rs:2-4](source.rs:2-4) notes
@@ -35,6 +35,12 @@ second (guide.md)
• # Explicit
Map (./guide.md:2-4) details
• # Inline
Map details
• # Plain
Map details
• # Source
source.rs:2-4 notes
@@ -136,6 +136,7 @@ fn inline_code_selection_copies_only_selected_content() {
for (source, selected) in [
("before `something` after", "something"),
("before `something` after", "some"),
("- # Reading\n `gauge` value", "aug"),
("before `something` after", "thing"),
("before `closeRequested_` after", "Requested"),
("before ``a`b`` after", "a`"),
@@ -259,7 +260,7 @@ fn inline_boundaries_preserve_selected_text_and_formatting() {
#[test]
fn lists_keep_nesting_and_paragraphs_without_sibling_spacers() {
let source = "3. first item long enough to wrap\n4. second item\n - nested `code`\n\n another paragraph\n - next nested\n5. final item\n\nOutside.";
let source = "3. first item long enough to wrap\n4. second item\n - nested `code`\n\n another paragraph\n - next nested\n5. final item\n\nOutside.\n\n- # Reading\n `gauge` value";
let mut copies = Vec::new();
for width in [24, 80] {
let layout = markdown_layout(source, width);
@@ -6,6 +6,9 @@ before `something` after
Selected "something" → ("something", PlainText)
before `something` after
Selected "some" → ("some", PlainText)
- # Reading
`gauge` value
Selected "aug" → ("aug", PlainText)
before `something` after
Selected "thing" → ("thing", PlainText)
before `closeRequested_` after
@@ -1,6 +1,5 @@
---
source: tui/src/transcript_view/markdown_copy_tests.rs
assertion_line: 76
expression: "copies[0]"
---
3. first item long enough to wrap
@@ -12,3 +11,6 @@ expression: "copies[0]"
5. final item
Outside.
- # Reading
`gauge` value