From 2d2d0e4b0b1ed499afd1e3aa7758af5af8806879 Mon Sep 17 00:00:00 2001 From: R4 Cheng Date: Tue, 20 Aug 2024 17:24:49 +0800 Subject: [PATCH] refactor: rename variable The fold chaining is to find max line number rather than line number width --- src/renderer/display_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/renderer/display_list.rs b/src/renderer/display_list.rs index 4858f2a..f438297 100644 --- a/src/renderer/display_list.rs +++ b/src/renderer/display_list.rs @@ -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| {