Refactor: simplify word navigation logic, improve line wrapping, and enhance parameter initialization across core and TUI modules.

This commit is contained in:
2025-09-30 02:54:07 +02:00
parent 8ee4c5f384
commit 053f389b1e
6 changed files with 27 additions and 45 deletions

View File

@@ -52,23 +52,21 @@ pub fn build_cursor_map(text: &str, width: u16) -> Vec<ScreenPos> {
word_start_col = col;
word_start_idx = byte_offset + grapheme.len();
}
} else {
if col + grapheme_width > width {
if word_start_col > 0 && byte_offset == word_start_idx {
// This is the first character of a new word that won't fit, wrap it
row += 1;
col = grapheme_width;
} else if word_start_col == 0 {
// No previous word boundary, hard break
row += 1;
col = grapheme_width;
} else {
// This is part of a word already on the line, let it extend beyond width
col += grapheme_width;
}
} else if col + grapheme_width > width {
if word_start_col > 0 && byte_offset == word_start_idx {
// This is the first character of a new word that won't fit, wrap it
row += 1;
col = grapheme_width;
} else if word_start_col == 0 {
// No previous word boundary, hard break
row += 1;
col = grapheme_width;
} else {
// This is part of a word already on the line, let it extend beyond width
col += grapheme_width;
}
} else {
col += grapheme_width;
}
// Set position for the end of this grapheme and any intermediate bytes