aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar lancebord 2026-03-08 22:54:13 -0400
committerGravatar lancebord 2026-03-08 22:54:13 -0400
commit34319b312e6d1ac2081a9473e5a2bdd756931b12 (patch)
tree0a2c16439e187727eddf2a3418169230b0510ec1
parentoff by one fix for some word wrapping (diff)
fixing text wrap miscalculation on long words
-rw-r--r--src/tui/ui.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 0fc1ec9..b026c34 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -129,6 +129,7 @@ fn count_wrapped_lines(lines: &[Line], width: usize) -> usize {
if width == 0 {
return lines.len();
}
+
lines
.iter()
.map(|line| {
@@ -146,13 +147,20 @@ fn count_wrapped_lines(lines: &[Line], width: usize) -> usize {
let mut current_width = 0;
for word in full_text.split_inclusive(' ') {
- let word_width = UnicodeWidthStr::width(word);
- if current_width > 0 && current_width + word_width > width {
- row_count += 1;
- current_width = word_width;
- } else {
+ let mut word_width = UnicodeWidthStr::width(word);
+ if current_width + word_width <= width {
current_width += word_width;
+ continue;
}
+
+ row_count += 1;
+
+ if word_width >= width {
+ row_count += word_width / width;
+ word_width %= width;
+ }
+
+ current_width = word_width;
}
row_count
})