renderer/metal: handle preedit wider than our screen

This commit is contained in:
Mitchell Hashimoto
2023-11-15 09:53:51 -08:00
parent 50f0aaf26b
commit 7457b40a45
2 changed files with 9 additions and 2 deletions

View File

@ -1101,10 +1101,9 @@ fn rebuildCells(
y: usize,
x: [2]usize,
} = if (preedit) |preedit_v| preedit: {
var x = screen.cursor.x;
break :preedit .{
.y = screen.cursor.y,
.x = .{ x, x + preedit_v.width() },
.x = preedit_v.range(screen.cursor.x, screen.cols - 1),
};
} else null;

View File

@ -48,4 +48,12 @@ pub const Preedit = struct {
return result;
}
pub fn range(self: *const Preedit, start: usize, max: usize) [2]usize {
// If our preedit goes off the end of the screen, we adjust it so
// that it shifts left.
const end = start + self.width();
const offset = if (end > max) end - max else 0;
return .{ start -| offset, end -| offset };
}
};