refactor: replace cursel_length with Buffer.Node.get_range

get_range is likely much faster because it only walks the buffer tree
once. Besides the performance difference it should give identical results.
This commit is contained in:
CJ van den Berg 2025-10-30 22:32:57 +01:00
parent 8246f2b0ba
commit 18bc89edf8
2 changed files with 2 additions and 22 deletions

View file

@ -1632,26 +1632,6 @@ pub const Editor = struct {
return self.primary.col - self.view.col;
}
pub fn cursel_length(root: Buffer.Root, cursel_: CurSel, metrics: Buffer.Metrics) usize {
var length: usize = 0;
var cursel = cursel_;
cursel.check_selection(root, metrics);
if (cursel.selection) |*sel| {
sel.normalize();
if (sel.begin.row == sel.end.row) {
length = sel.end.col - sel.begin.col;
} else {
var row = sel.begin.row;
while (row < sel.end.row) {
length += root.line_width(row, metrics) catch 0;
row += 1;
}
length = length + sel.end.col - sel.begin.col;
}
}
return length;
}
fn update_event(self: *Self) !void {
const primary = self.get_primary();
const dirty = if (self.buffer) |buf| buf.is_dirty() else false;