From 79c03a41431e488c4c7e7df85652a380eaef496b Mon Sep 17 00:00:00 2001 From: Cyprien de Saint Guilhem Date: Thu, 12 Dec 2024 11:36:44 +0100 Subject: [PATCH] Fix trimming issue --- src/format.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/format.rs b/src/format.rs index 78a5461..f2a70e4 100644 --- a/src/format.rs +++ b/src/format.rs @@ -129,12 +129,21 @@ pub fn format_file( // removing the re-wrapped text. let (linum_old, next_line) = queue.pop_front().unwrap(); // Doesn't panic because we can re-wrap. + let trimmed_next_line = next_line.trim_start(); + // Append the re-wrapped words to the current line - line = [line.as_str(), " ", &next_line[0..rewrap_point]] - .concat(); + line = [ + line.as_str(), + " ", + &trimmed_next_line[0..rewrap_point], + ] + .concat(); + + println!("Re-wrapped: {line}"); // Select the line left after re-wrapping - let next_line = next_line[rewrap_point..].trim_start(); + let next_line = + trimmed_next_line[rewrap_point..].trim_start(); // Add to the queue if there text left in the next line if !next_line.is_empty() {