Split code blocks into multiple rich_text lines
This improves layout diffing considerably!
This commit is contained in:
parent
c2155b82b3
commit
eb81679e60
1 changed files with 12 additions and 10 deletions
|
|
@ -116,7 +116,7 @@ pub enum Item {
|
||||||
/// A code block.
|
/// A code block.
|
||||||
///
|
///
|
||||||
/// You can enable the `highlighter` feature for syntax highlighting.
|
/// You can enable the `highlighter` feature for syntax highlighting.
|
||||||
CodeBlock(Text),
|
CodeBlock(Vec<Text>),
|
||||||
/// A list.
|
/// A list.
|
||||||
List {
|
List {
|
||||||
/// The first number of the list, if it is ordered.
|
/// The first number of the list, if it is ordered.
|
||||||
|
|
@ -377,6 +377,7 @@ fn parse_with<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
|
let mut code = Vec::new();
|
||||||
let mut strong = false;
|
let mut strong = false;
|
||||||
let mut emphasis = false;
|
let mut emphasis = false;
|
||||||
let mut strikethrough = false;
|
let mut strikethrough = false;
|
||||||
|
|
@ -587,7 +588,7 @@ fn parse_with<'a>(
|
||||||
produce(
|
produce(
|
||||||
state.borrow_mut(),
|
state.borrow_mut(),
|
||||||
&mut lists,
|
&mut lists,
|
||||||
Item::CodeBlock(Text::new(spans.drain(..).collect())),
|
Item::CodeBlock(code.drain(..).collect()),
|
||||||
source,
|
source,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -605,9 +606,9 @@ fn parse_with<'a>(
|
||||||
#[cfg(feature = "highlighter")]
|
#[cfg(feature = "highlighter")]
|
||||||
if let Some(highlighter) = &mut highlighter {
|
if let Some(highlighter) = &mut highlighter {
|
||||||
for line in text.lines() {
|
for line in text.lines() {
|
||||||
spans.extend_from_slice(
|
code.push(Text::new(
|
||||||
highlighter.highlight_line(&format!("{line}\n")),
|
highlighter.highlight_line(line).to_vec(),
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -871,13 +872,14 @@ where
|
||||||
}))
|
}))
|
||||||
.spacing(spacing * 0.75)
|
.spacing(spacing * 0.75)
|
||||||
.into(),
|
.into(),
|
||||||
Item::CodeBlock(code) => container(
|
Item::CodeBlock(lines) => container(
|
||||||
scrollable(
|
scrollable(
|
||||||
container(
|
container(column(lines.iter().map(|line| {
|
||||||
rich_text(code.spans(style))
|
rich_text(line.spans(style))
|
||||||
.font(Font::MONOSPACE)
|
.font(Font::MONOSPACE)
|
||||||
.size(code_size),
|
.size(code_size)
|
||||||
)
|
.into()
|
||||||
|
})))
|
||||||
.padding(spacing.0 / 2.0),
|
.padding(spacing.0 / 2.0),
|
||||||
)
|
)
|
||||||
.direction(scrollable::Direction::Horizontal(
|
.direction(scrollable::Direction::Horizontal(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue