fix: allow indenting of blank lines if there is just one cursor
This commit is contained in:
parent
5e292e75b5
commit
8be5a14eda
1 changed files with 5 additions and 5 deletions
|
|
@ -3778,12 +3778,12 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const toggle_comment_meta: Meta = .{ .description = "Toggle comment" };
|
pub const toggle_comment_meta: Meta = .{ .description = "Toggle comment" };
|
||||||
|
|
||||||
fn indent_cursor(self: *Self, root: Buffer.Root, cursor: Cursor, allocator: Allocator) error{Stop}!Buffer.Root {
|
fn indent_cursor(self: *Self, root: Buffer.Root, cursor: Cursor, no_blank_line: bool, allocator: Allocator) error{Stop}!Buffer.Root {
|
||||||
const space = " ";
|
const space = " ";
|
||||||
var cursel: CurSel = .{};
|
var cursel: CurSel = .{};
|
||||||
cursel.cursor = cursor;
|
cursel.cursor = cursor;
|
||||||
try move_cursor_begin(root, &cursel.cursor, self.metrics);
|
try move_cursor_begin(root, &cursel.cursor, self.metrics);
|
||||||
if (root.line_width(cursel.cursor.row, self.metrics) catch 0 == 0)
|
if (no_blank_line and (root.line_width(cursel.cursor.row, self.metrics) catch 0 == 0))
|
||||||
return root;
|
return root;
|
||||||
switch (self.indent_mode) {
|
switch (self.indent_mode) {
|
||||||
.spaces, .auto => {
|
.spaces, .auto => {
|
||||||
|
|
@ -3803,13 +3803,13 @@ pub const Editor = struct {
|
||||||
const sel_from_start = sel_.begin.col == 0;
|
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, true, 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, true, allocator);
|
||||||
if (sel_from_start)
|
if (sel_from_start)
|
||||||
sel_.begin.col = 0;
|
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, self.cursels.items.len > 1, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn indent(self: *Self, ctx: Context) Result {
|
pub fn indent(self: *Self, ctx: Context) Result {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue