fix: clamp to end of last line if the cursor is past the end of the buffer

closes #289
This commit is contained in:
CJ van den Berg 2025-09-09 09:24:18 +02:00
parent 251c74a23b
commit fda9338a06
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -28,8 +28,12 @@ pub inline fn right_of(self: Self, other: Self) bool {
}
pub fn clamp_to_buffer(self: *Self, root: Buffer.Root, metrics: Metrics) void {
self.row = @min(self.row, root.lines() - 1);
if (self.row > root.lines() - 1) {
self.row = root.lines() - 1;
self.col = root.line_width(self.row, metrics) catch 0;
} else {
self.col = @min(self.col, root.line_width(self.row, metrics) catch 0);
}
}
fn follow_target(self: *Self, root: Buffer.Root, metrics: Metrics) void {