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:
parent
be41027d75
commit
4a0150d68f
3 changed files with 80 additions and 68 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,17 @@ pub fn from_pos(sel: Self, root: Buffer.Root, metrics: Buffer.Metrics) Self {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn from_range(range: anytype, root: Buffer.Root, metrics: Buffer.Metrics) Self {
|
||||
return from_pos(from_range_raw(range), root, metrics);
|
||||
}
|
||||
|
||||
pub fn from_range_raw(range: anytype) Self {
|
||||
return .{
|
||||
.begin = .{ .row = range.start_point.row, .col = range.start_point.column },
|
||||
.end = .{ .row = range.end_point.row, .col = range.end_point.column },
|
||||
};
|
||||
}
|
||||
|
||||
pub fn line_from_cursor(cursor: Cursor, root: Buffer.Root, mtrx: Buffer.Metrics) Self {
|
||||
var begin = cursor;
|
||||
var end = cursor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue