From c527f2e212ba126dc53a4e8fc33e3e0cdc67e5e2 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Tue, 5 Nov 2024 13:58:07 -0800 Subject: [PATCH] Prevent extra line break on long token at start of rewrap (#20256) Closes #19532 Release Notes: - Fixed a bug where rewrapping with a long word at the start of the line would cause a new line to be inserted. Co-authored-by: Will Bradley --- crates/editor/src/editor.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4296d15f2a2113feb0674dabeb414e7dfc2c1c07..205d94b5a988911c2fe13d9685d983fcf2b50b84 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -13264,7 +13264,7 @@ fn wrap_with_prefix( is_whitespace, } in tokenizer { - if current_line_len + grapheme_len > wrap_column { + if current_line_len + grapheme_len > wrap_column && current_line_len != line_prefix_len { wrapped_text.push_str(current_line.trim_end()); wrapped_text.push('\n'); current_line.truncate(line_prefix.len()); @@ -13290,6 +13290,15 @@ fn wrap_with_prefix( #[test] fn test_wrap_with_prefix() { + assert_eq!( + wrap_with_prefix( + "# ".to_string(), + "abcdefg".to_string(), + 4, + NonZeroU32::new(4).unwrap() + ), + "# abcdefg" + ); assert_eq!( wrap_with_prefix( "".to_string(),