on master help sign in
update `x_offset` calculation in Buffer::set_string_truncated (#3839)

when `truncate_start` is `true`, the `x_offset` is now properly updated according to the width of the content or the truncated length.

commit7483c762229516298c4a2d9398b9418dbc57198b authorkristopherbullinger <38427362+kristopherbullinger@users.noreply.github.com> dateWed 16 Nov 2022, 20:06 (4 years ago) parent9434635
1 file changed+4−3
helix-tui/src/buffer.rs+4−3
helix-tui/src/buffer.rs+4−3
@@ -360,14 +360,14 @@ impl Buffer {
360360 let mut start_index = self.index_of(x, y);
361361 let mut index = self.index_of(max_offset as u16, y);
362362
363− let total_width = string.width();
364− let truncated = total_width > width;
363+ let content_width = string.width();
364+ let truncated = content_width > width;
365365 if ellipsis && truncated {
366366 self.content[start_index].set_symbol("…");
367367 start_index += 1;
368368 }
369369 if !truncated {
370− index -= width - total_width;
370+ index -= width - content_width;
371371 }
372372 for (byte_offset, s) in graphemes.rev() {
373373 let width = s.width();
@@ -384,6 +384,7 @@ impl Buffer {
384384 self.content[i].reset();
385385 }
386386 index -= width;
387+ x_offset += width;
387388 }
388389 }
389390 (x_offset as u16, y)