mirror of https://github.com/helix-editor/helix
Only insert hard-wraps at whitespace.
This is a better behavior for :reflow since it prevents breaking URLs across lines.pull/11738/head
parent
b6dc0573df
commit
df264ffbb4
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue