Skip to content

Commit

Permalink
fix panic when highlighter cache is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall committed Sep 3, 2019
1 parent 3100088 commit e484049
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit e484049

Please sign in to comment.