Skip to content

Commit

Permalink
Fix multiple Text events inside code block on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Mar 22, 2024
1 parent 520fb4a commit b2093f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions book/src/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ pub fn main() -> iced::Result {
# Decrement,
# }
#
# fn update(value: &mut u64, message: Message) {
# fn update(value: &mut i64, message: Message) {
# match message {
# Message::Decrement => *value -= 1,
# }
# }
#
# fn view(value: &u64) -> Column<Message> {
# fn view(value: &i64) -> Column<Message> {
# column![
# text(value),
# button("-").on_press(Message::Decrement),
Expand Down
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn process_chapter(
let output = groups.into_iter().flat_map(|(is_iced_code, group)| {
if is_iced_code {
let mut events = Vec::new();
let mut code = String::new();

for event in group {
if let Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(label))) = &event {
Expand All @@ -111,20 +112,26 @@ fn process_chapter(
)
});

code.clear();
icebergs.push(None);
heights.push(height);
events.push(event);
} else if let Event::Text(code) = &event {
if let Ok(iceberg) = compiler.compile(code) {
if let Some(last_iceberg) = icebergs.last_mut() {
*last_iceberg = Some(iceberg);
}
} else if let Event::Text(text) = &event {
if !code.ends_with('\n') {
code.push('\n');
}

code.push_str(text);
events.push(event);
} else if let Event::End(TagEnd::CodeBlock) = &event {
events.push(event);

if let Ok(iceberg) = compiler.compile(&code) {
if let Some(last_iceberg) = icebergs.last_mut() {
*last_iceberg = Some(iceberg);
}
}

if is_first {
is_first = false;

Expand Down

0 comments on commit b2093f1

Please sign in to comment.