mirror of
https://github.com/helix-editor/helix.git
synced 2025-04-04 19:37:54 +03:00
11 lines
465 B
Rust
11 lines
465 B
Rust
use smartstring::{LazyCompact, SmartString};
|
|
use textwrap::{Options, WordSplitter::NoHyphenation};
|
|
|
|
/// Given a slice of text, return the text re-wrapped to fit it
|
|
/// within the given width.
|
|
pub fn reflow_hard_wrap(text: &str, text_width: usize) -> SmartString<LazyCompact> {
|
|
let options = Options::new(text_width)
|
|
.word_splitter(NoHyphenation)
|
|
.word_separator(textwrap::WordSeparator::AsciiSpace);
|
|
textwrap::refill(text, options).into()
|
|
}
|