Skip to content

Commit 6dc3b1d

Browse files
committed
fix: crash on resize
1 parent 7692bc1 commit 6dc3b1d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/app.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,15 +649,14 @@ fn fit_text(
649649
}),
650650
)
651651
} else {
652-
let mut str = l.chars().take(cols + 1).collect::<String>();
653-
if str.chars().count() > cols {
654-
str.truncate(cols - 1);
655-
Either::Right(once(Line::default().spans(vec![
656-
Span::raw(str),
657-
Span::styled("…", Style::default().add_modifier(Modifier::DIM)),
658-
])))
659-
} else {
660-
Either::Right(once(Line::raw(str)))
652+
match l.chars().nth(cols) {
653+
Some(_) => { // has more chars than cols
654+
Either::Right(once(Line::default().spans(vec![
655+
Span::raw(l.chars().take(cols - 1).collect::<String>()),
656+
Span::styled("…", Style::default().add_modifier(Modifier::DIM)),
657+
])))
658+
}
659+
None => Either::Right(once(Line::raw(l.chars().take(cols).collect::<String>()))),
661660
}
662661
};
663662
match anchor {

0 commit comments

Comments
 (0)