Skip to content

Commit

Permalink
Discard markdown::Highlighter if language changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 31, 2025
1 parent 095859e commit 447f5ae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions widget/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ struct State {
#[derive(Debug)]
struct Highlighter {
lines: Vec<(String, Vec<Span>)>,
language: String,
parser: iced_highlighter::Stream,
current: usize,
}
Expand All @@ -304,6 +305,7 @@ impl Highlighter {
token: language.to_string(),
},
),
language: language.to_owned(),
current: 0,
}
}
Expand Down Expand Up @@ -484,6 +486,9 @@ fn parse_with<'a>(
.borrow_mut()
.highlighter
.take()
.filter(|highlighter| {
highlighter.language == _language.as_ref()
})
.unwrap_or_else(|| Highlighter::new(&_language));

highlighter.prepare();
Expand Down

0 comments on commit 447f5ae

Please sign in to comment.