Skip to content

Commit

Permalink
Prevent extra line break on long token at start of rewrap (#20256)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mikayla-maki and wbbradley authored Nov 5, 2024
1 parent 47defa2 commit c527f2e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(),
Expand Down

0 comments on commit c527f2e

Please sign in to comment.