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 <will@zed.dev>
This commit is contained in:
Mikayla Maki 2024-11-05 13:58:07 -08:00 committed by GitHub
parent 47defa2849
commit c527f2e212
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13264,7 +13264,7 @@ fn wrap_with_prefix(
is_whitespace, is_whitespace,
} in tokenizer } 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_str(current_line.trim_end());
wrapped_text.push('\n'); wrapped_text.push('\n');
current_line.truncate(line_prefix.len()); current_line.truncate(line_prefix.len());
@ -13290,6 +13290,15 @@ fn wrap_with_prefix(
#[test] #[test]
fn test_wrap_with_prefix() { fn test_wrap_with_prefix() {
assert_eq!(
wrap_with_prefix(
"# ".to_string(),
"abcdefg".to_string(),
4,
NonZeroU32::new(4).unwrap()
),
"# abcdefg"
);
assert_eq!( assert_eq!(
wrap_with_prefix( wrap_with_prefix(
"".to_string(), "".to_string(),