fix: if selection starts at BOL when indenting keep it there after indenting

This commit is contained in:
CJ van den Berg 2024-12-06 21:26:10 +01:00
parent d26d830246
commit dbc4707001
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -2580,14 +2580,17 @@ pub const Editor = struct {
} }
fn indent_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { fn indent_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root {
if (cursel.selection) |sel_| { if (cursel.selection) |*sel_| {
var root = root_; var root = root_;
var sel = sel_; var sel = sel_.*;
const sel_from_start = sel_.begin.col == 0;
sel.normalize(); sel.normalize();
while (sel.begin.row < sel.end.row) : (sel.begin.row += 1) while (sel.begin.row < sel.end.row) : (sel.begin.row += 1)
root = try self.indent_cursor(root, sel.begin, allocator); root = try self.indent_cursor(root, sel.begin, allocator);
if (sel.end.col > 0) if (sel.end.col > 0)
root = try self.indent_cursor(root, sel.end, allocator); root = try self.indent_cursor(root, sel.end, allocator);
if (sel_from_start)
sel_.begin.col = 0;
return root; return root;
} else return try self.indent_cursor(root_, cursel.cursor, allocator); } else return try self.indent_cursor(root_, cursel.cursor, allocator);
} }