refactor: add Cursor.from_pos and Seleciton.from_range

And use them to clean-up all root.pos_to_width call sites.
This commit is contained in:
CJ van den Berg 2025-11-25 14:37:05 +01:00
parent be41027d75
commit 4a0150d68f
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 80 additions and 68 deletions

View file

@ -42,6 +42,13 @@ fn follow_target(self: *Self, root: Buffer.Root, metrics: Metrics) void {
self.col = @min(self.target, root.line_width(self.row, metrics) catch 0);
}
pub fn from_pos(self: Self, root: Buffer.Root, metrics: Buffer.Metrics) Self {
return .{
.row = self.row,
.col = root.pos_to_width(self.row, self.col, metrics) catch root.line_width(self.row, metrics) catch 0,
};
}
fn move_right_no_target(self: *Self, root: Buffer.Root, metrics: Metrics) !void {
const lines = root.lines();
if (lines <= self.row) return error.Stop;