Skip to content

Commit 8941d5e

Browse files
tgolssondjc
authored andcommitted
simplify from feedback
1 parent 4909897 commit 8941d5e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/multi.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,16 @@ enum InsertLocation {
519519
Before(usize),
520520
}
521521

522-
// Calculate real length based on terminal width
523-
// This take in account linewrap from terminal
524-
fn visual_line_count<StrRef: AsRef<str>>(lines: &[StrRef], width: f64) -> usize {
525-
lines.iter().fold(0, |sum, val| {
526-
sum + if val.as_ref().is_empty() {
527-
1
528-
} else {
529-
let effective_line_length = console::measure_text_width(val.as_ref()) as f64;
530-
usize::max((effective_line_length / width).ceil() as usize, 1)
531-
}
532-
})
522+
/// Calculate the number of visual lines in the given lines, after
523+
/// accounting for line wrapping and non-printable characters.
524+
fn visual_line_count(lines: &[impl AsRef<str>], width: f64) -> usize {
525+
let mut real_lines = 0;
526+
for line in lines {
527+
let effective_line_length = console::measure_text_width(line.as_ref()) as f64;
528+
real_lines += usize::max((effective_line_length / width).ceil() as usize, 1);
529+
}
530+
531+
real_lines
533532
}
534533

535534
#[cfg(test)]

0 commit comments

Comments
 (0)