mirror of https://github.com/helix-editor/helix
add reflow command (#2128)
* add reflow command Users need to be able to hard-wrap text for many applications, including comments in code, git commit messages, plaintext documentation, etc. It often falls to the user to manually insert line breaks where appropriate in order to hard-wrap text. This commit introduces the "reflow" command (both in the TUI and core library) to automatically hard-wrap selected text to a given number of characters (defined by Unicode "extended grapheme clusters"). It handles lines with a repeated prefix, such as comments ("//") and indentation. * reflow: consider newlines to be word separators * replace custom reflow impl with textwrap crate * Sync reflow command docs with book * reflow: add default max_line_len language setting Co-authored-by: Vince Mutolo <vince@mutolo.org>pull/2372/head
parent
567ddef388
commit
f9baced216
@ -0,0 +1,7 @@
|
|||||||
|
use smartstring::{LazyCompact, SmartString};
|
||||||
|
|
||||||
|
/// Given a slice of text, return the text re-wrapped to fit it
|
||||||
|
/// within the given width.
|
||||||
|
pub fn reflow_hard_wrap(text: &str, max_line_len: usize) -> SmartString<LazyCompact> {
|
||||||
|
textwrap::refill(text, max_line_len).into()
|
||||||
|
}
|
Loading…
Reference in New Issue