Only insert hard-wraps at whitespace.

This is a better behavior for :reflow since it prevents breaking URLs
across lines.
pull/11738/head
Rose Hogenson 2025-02-25 16:15:41 -08:00
parent b6dc0573df
commit df264ffbb4
6 changed files with 9 additions and 7 deletions

View File

@ -136,10 +136,6 @@ impl<'a> GraphemeWithSource<'a> {
fn width(&self) -> usize {
self.grapheme.width()
}
fn is_word_boundary(&self) -> bool {
self.grapheme.is_word_boundary()
}
}
#[derive(Debug, Clone)]
@ -153,6 +149,7 @@ pub struct TextFormat {
pub viewport_width: u16,
pub soft_wrap_at_text_width: bool,
pub continue_comments: Vec<String>,
pub is_word_boundary: fn(&Grapheme) -> bool,
}
// test implementation is basically only used for testing or when softwrap is always disabled
@ -168,6 +165,7 @@ impl Default for TextFormat {
wrap_indicator_highlight: None,
soft_wrap_at_text_width: false,
continue_comments: Vec::new(),
is_word_boundary: |g| g.is_word_boundary(),
}
}
}
@ -418,7 +416,7 @@ impl<'t> DocumentFormatter<'t> {
self.indent_level = None;
}
let is_word_boundary = grapheme.is_word_boundary();
let is_word_boundary = (self.text_fmt.is_word_boundary)(&grapheme.grapheme);
word_width += grapheme.width();
self.word_buf.push(grapheme);

View File

@ -14,6 +14,7 @@ impl TextFormat {
viewport_width: 17,
soft_wrap_at_text_width: false,
continue_comments: Vec::new(),
is_word_boundary: |g| g.is_word_boundary(),
}
}
}

View File

@ -2175,6 +2175,7 @@ fn reflow(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyho
.and_then(|config| config.comment_tokens.as_deref())
.unwrap_or(&[]),
),
is_word_boundary: |g| g.is_whitespace(),
};
let annotations = TextAnnotations::default();

View File

@ -892,9 +892,9 @@ bla]#",
.await?;
test((
"#[|Very_long_words_should_not_be_broken_by_hard_wrap]#",
"#[|Very-long-words-should-not-be-broken-by-hard-wrap]#",
":reflow 2<ret>",
"#[|Very_long_words_should_not_be_broken_by_hard_wrap]#",
"#[|Very-long-words-should-not-be-broken-by-hard-wrap]#",
))
.await?;

View File

@ -103,6 +103,7 @@ impl InlineDiagnosticsConfig {
viewport_width: width,
soft_wrap_at_text_width: true,
continue_comments: Vec::new(),
is_word_boundary: |g| g.is_word_boundary(),
}
}
}

View File

@ -2222,6 +2222,7 @@ impl Document {
.map(Highlight),
soft_wrap_at_text_width,
continue_comments: Vec::new(),
is_word_boundary: |g| g.is_word_boundary(),
}
}