Skip to content

Commit 0a606ab

Browse files
committed
Fix word width calculation
+1 to include whitespace. This caused indentation issues when the line was exactly as long as the terminal width.
1 parent 5b2023f commit 0a606ab

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/output.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ impl<'a> PageRenderer<'a> {
231231
for w in words {
232232
let mut w_width = w.width();
233233
let backtick_count = w.chars().filter(|x| *x == '`').count();
234+
// Backticks won't be displayed.
234235
w_width -= backtick_count;
235236

236-
if cur_width + w_width > max_len && cur_width != base_width {
237+
// current + word + space after the word
238+
if cur_width + w_width + 1 > max_len && cur_width != base_width {
237239
// If the next word is added, the line will be longer than the configured line
238240
// length.
239241
//
@@ -263,6 +265,9 @@ impl<'a> PageRenderer<'a> {
263265
buf += w;
264266
cur_width += w_width;
265267

268+
// If there are two backticks in `w`, then `w` contains all the highlighted text.
269+
// If there is only one (e.g `ab cd` => split into words ["`ab", "cd`"]), it
270+
// starts/ends the highlight.
266271
if backtick_count == 1 {
267272
inside_hl = !inside_hl;
268273
}

0 commit comments

Comments
 (0)