Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic when highlighter cache is empty #259

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/highlighting/highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a, 'b> Iterator for RangedHighlightIterator<'a, 'b> {
(self.text.len(), ScopeStackOp::Noop)
};
// println!("{} - {:?} {}:{}", self.index, self.pos, self.state.path.len(), self.state.styles.len());
let style = *self.state.styles.last().unwrap();
let style = *self.state.styles.last().unwrap_or(&Style::default());
let text = &self.text[self.pos..end];
let range = Range { start: self.pos, end: end };
{
Expand All @@ -147,8 +147,11 @@ impl<'a, 'b> Iterator for RangedHighlightIterator<'a, 'b> {
BasicScopeStackOp::Push(_) => {
// we can push multiple times so this might have changed
let new_cache = {
let prev_cache = m_caches.last().unwrap();
highlighter.update_single_cache_for_push(prev_cache, cur_stack)
if let Some(prev_cache) = m_caches.last() {
highlighter.update_single_cache_for_push(prev_cache, cur_stack)
} else {
highlighter.update_single_cache_for_push(&ScoredStyle::from_style(highlighter.get_default()), cur_stack)
}
};
m_styles.push(highlighter.finalize_style_with_multis(&new_cache, cur_stack));
m_caches.push(new_cache);
Expand Down