Skip to content

Commit

Permalink
refactor: rename variable
Browse files Browse the repository at this point in the history
	The fold chaining is to find max line number rather than line number width
  • Loading branch information
chengr4 committed Aug 20, 2024
1 parent 4ba7683 commit 2d2d0e4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/renderer/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ impl<'a> fmt::Debug for DisplayList<'a> {

impl<'a> Display for DisplayList<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let lineno_width = self.body.iter().fold(0, |max, set| {
let max_lineno = self.body.iter().fold(0, |max, set| {
set.display_lines.iter().fold(max, |max, line| match line {
DisplayLine::Source { lineno, .. } => cmp::max(lineno.unwrap_or(0), max),
_ => max,
})
});
let lineno_width = if lineno_width == 0 {
lineno_width + 1
let lineno_width = if max_lineno == 0 {
1
} else if self.anonymized_line_numbers {
ANONYMIZED_LINE_NUM.len()
} else {
((lineno_width as f64).log10().floor() as usize) + 1
((max_lineno as f64).log10().floor() as usize) + 1
};

let multiline_depth = self.body.iter().fold(0, |max, set| {
Expand Down

0 comments on commit 2d2d0e4

Please sign in to comment.