fix: left an right movements jump to selection boundary
When there is an active selection, basic left and right movements should cancel the selection and place the cursor on the left/right of where the selection was. closes #244
This commit is contained in:
parent
1eb36696d2
commit
6618a2d84d
1 changed files with 29 additions and 5 deletions
|
@ -3042,17 +3042,41 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
pub const join_next_line_meta: Meta = .{ .description = "Join next line", .arguments = &.{.integer} };
|
pub const join_next_line_meta: Meta = .{ .description = "Join next line", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn move_left(self: *Self, ctx: Context) Result {
|
fn move_cursors_or_collapse_selection(
|
||||||
|
self: *Self,
|
||||||
|
direction: enum { left, right },
|
||||||
|
ctx: Context,
|
||||||
|
) error{Stop}!void {
|
||||||
const root = try self.buf_root();
|
const root = try self.buf_root();
|
||||||
self.with_cursors_const_repeat(root, move_cursor_left, ctx) catch {};
|
var repeat: usize = 1;
|
||||||
|
_ = ctx.args.match(.{tp.extract(&repeat)}) catch false;
|
||||||
|
while (repeat > 0) : (repeat -= 1) {
|
||||||
|
for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
|
if (cursel.selection) |*sel| {
|
||||||
|
cursel.cursor = switch (direction) {
|
||||||
|
.left => if (sel.is_reversed()) sel.end else sel.begin,
|
||||||
|
.right => if (sel.is_reversed()) sel.begin else sel.end,
|
||||||
|
};
|
||||||
|
cursel.disable_selection(root, self.metrics);
|
||||||
|
} else {
|
||||||
|
try with_cursor_const(root, switch (direction) {
|
||||||
|
.left => move_cursor_left,
|
||||||
|
.right => move_cursor_right,
|
||||||
|
}, cursel, self.metrics);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
self.collapse_cursors();
|
||||||
|
}
|
||||||
self.clamp();
|
self.clamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn move_left(self: *Self, ctx: Context) Result {
|
||||||
|
self.move_cursors_or_collapse_selection(.left, ctx) catch {};
|
||||||
|
}
|
||||||
pub const move_left_meta: Meta = .{ .description = "Move cursor left", .arguments = &.{.integer} };
|
pub const move_left_meta: Meta = .{ .description = "Move cursor left", .arguments = &.{.integer} };
|
||||||
|
|
||||||
pub fn move_right(self: *Self, ctx: Context) Result {
|
pub fn move_right(self: *Self, ctx: Context) Result {
|
||||||
const root = try self.buf_root();
|
self.move_cursors_or_collapse_selection(.right, ctx) catch {};
|
||||||
self.with_cursors_const_repeat(root, move_cursor_right, ctx) catch {};
|
|
||||||
self.clamp();
|
|
||||||
}
|
}
|
||||||
pub const move_right_meta: Meta = .{ .description = "Move cursor right", .arguments = &.{.integer} };
|
pub const move_right_meta: Meta = .{ .description = "Move cursor right", .arguments = &.{.integer} };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue