Skip to content

Commit

Permalink
update x_offset calculation in Buffer::set_string_truncated
Browse files Browse the repository at this point in the history
when `truncate_start` is `true`, the `x_offset` is now properly updated
according to the width of the content or the truncated length.
  • Loading branch information
kristopherbullinger committed Sep 13, 2022
1 parent ec81ec1 commit 9b9cf88
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -367,6 +367,7 @@ impl Buffer {
self.content[i].reset();
}
index -= width;
x_offset += width;
}
}
(x_offset as u16, y)
Expand Down

0 comments on commit 9b9cf88

Please sign in to comment.