Fix grapheme indexing

pull/11738/head
Rose Hogenson 2025-03-31 12:16:36 -07:00
parent aed244f127
commit 4d64d670dd
2 changed files with 18 additions and 1 deletions

View File

@ -518,7 +518,7 @@ pub fn reflow(text: RopeSlice, char_pos: usize, opts: &ReflowOpts) -> Vec<Change
let mut word_width = 0;
let mut last_word_boundary = None;
let mut changes = Vec::new();
for grapheme in text.graphemes() {
for grapheme in text.slice(char_pos..).graphemes() {
let grapheme_chars = grapheme.len_chars();
let mut grapheme = Grapheme::new(GraphemeStr::from(Cow::from(grapheme)), col, TAB_WIDTH);
if col + grapheme.width() > opts.width && !grapheme.is_whitespace() {

View File

@ -910,5 +910,22 @@ wrapping]#",
))
.await?;
test((
"Test wrapping only part of the text
#[|wrapping should only modify the lines that are currently selected
]#",
":reflow 11<ret>",
"Test wrapping only part of the text
#[|wrapping
should only
modify the
lines that
are
currently
selected
]#",
))
.await?;
Ok(())
}