Properly calculate string lengths

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-02-08 22:04:09 +01:00
parent e9e2d51261
commit 941b7e0dae
8 changed files with 28 additions and 24 deletions

View File

@@ -123,7 +123,7 @@ pub fn draw(self: Text) void {
if (self.maybe_mask) |mask| {
if (self.width < 1) return;
const length = @min(self.text.items.len, self.width - 1);
const length = @min(TerminalBuffer.strWidth(self.text.items), self.width - 1);
if (length == 0) return;
TerminalBuffer.drawCharMultiple(
@@ -138,11 +138,12 @@ pub fn draw(self: Text) void {
return;
}
const length = @min(self.text.items.len, self.width);
const str_length = TerminalBuffer.strWidth(self.text.items);
const length = @min(str_length, self.width);
if (length == 0) return;
const visible_slice = vs: {
if (self.text.items.len > self.width and self.cursor < self.text.items.len) {
if (str_length > self.width and self.cursor < str_length) {
break :vs self.text.items[self.visible_start..(self.width + self.visible_start)];
} else {
break :vs self.text.items[self.visible_start..];