From 9b9cf882e5290e6152034e95b29d31cdbc69f08b Mon Sep 17 00:00:00 2001 From: kristopher Date: Tue, 13 Sep 2022 17:04:48 -0400 Subject: [PATCH] update `x_offset` calculation in Buffer::set_string_truncated when `truncate_start` is `true`, the `x_offset` is now properly updated according to the width of the content or the truncated length. --- helix-tui/src/buffer.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/helix-tui/src/buffer.rs b/helix-tui/src/buffer.rs index 21c53aadf9bc..938961cf6169 100644 --- a/helix-tui/src/buffer.rs +++ b/helix-tui/src/buffer.rs @@ -343,14 +343,14 @@ impl Buffer { let mut start_index = self.index_of(x, y); let mut index = self.index_of(max_offset as u16, y); - let total_width = string.width(); - let truncated = total_width > width; + let content_width = string.width(); + let truncated = content_width > width; if ellipsis && truncated { self.content[start_index].set_symbol("…"); start_index += 1; } if !truncated { - index -= width - total_width; + index -= width - content_width; } for (byte_offset, s) in graphemes.rev() { let width = s.width(); @@ -367,6 +367,7 @@ impl Buffer { self.content[i].reset(); } index -= width; + x_offset += width; } } (x_offset as u16, y)