feat: Helix & Vim mode: adding more commands (#218)
* Helix mode: select_left * select_to_char_right implementation * Vim select_to_char_left * Helix select_to_char_left * Helix & Vim: select_end * select_to_char_left: Avoid panic with no selection * select_left_helix: handling panic and shrinking code * Correcting helix left and right select * Helix mode: select_left * select_to_char_right implementation * Vim select_to_char_left * Helix select_to_char_left * Helix & Vim: select_end * select_to_char_left: Avoid panic with no selection * select_left_helix: handling panic and shrinking code * Correcting helix left and right select * Enable_selection on init_command * move_to_char modification * move_or_select --------- Co-authored-by: CJ van den Berg <cj@vdbonline.com>
This commit is contained in:
parent
716f871d03
commit
fb985a703a
6 changed files with 126 additions and 43 deletions
|
@ -8,6 +8,7 @@ const tui = @import("../tui.zig");
|
|||
const Editor = @import("../editor.zig").Editor;
|
||||
const Buffer = @import("Buffer");
|
||||
const Cursor = Buffer.Cursor;
|
||||
const Selection = Buffer.Selection;
|
||||
|
||||
var commands: Commands = undefined;
|
||||
|
||||
|
@ -135,6 +136,73 @@ const cmds_ = struct {
|
|||
ed.clamp();
|
||||
}
|
||||
pub const cut_forward_internal_inclusive_meta: Meta = .{ .description = "Cut next character to internal clipboard (inclusive)" };
|
||||
|
||||
pub fn select_right_helix(_: *void, _: Ctx) Result {
|
||||
const mv = tui.mainview() orelse return;
|
||||
const ed = mv.get_active_editor() orelse return;
|
||||
const root = try ed.buf_root();
|
||||
|
||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||
const sel = try cursel.enable_selection(root, ed.metrics);
|
||||
|
||||
// handling left to right transition
|
||||
const sel_begin: i32 = @intCast(sel.begin.col);
|
||||
const sel_end: i32 = @intCast(sel.end.col);
|
||||
if ((sel_begin - sel_end) == 1 and sel.begin.row == sel.end.row) {
|
||||
try Editor.move_cursor_right(root, &sel.end, ed.metrics);
|
||||
sel.begin.col -= 1;
|
||||
}
|
||||
|
||||
try Editor.move_cursor_right(root, &sel.end, ed.metrics);
|
||||
cursel.cursor = sel.end;
|
||||
cursel.check_selection(root, ed.metrics);
|
||||
};
|
||||
ed.clamp();
|
||||
}
|
||||
pub const select_right_helix_meta: Meta = .{ .description = "Select right" };
|
||||
|
||||
pub fn select_left_helix(_: *void, _: Ctx) Result {
|
||||
const mv = tui.mainview() orelse return;
|
||||
const ed = mv.get_active_editor() orelse return;
|
||||
const root = try ed.buf_root();
|
||||
|
||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||
if (cursel.selection == null) {
|
||||
cursel.selection = Selection.from_cursor(&cursel.cursor);
|
||||
try cursel.selection.?.begin.move_right(root, ed.metrics);
|
||||
}
|
||||
if (cursel.selection) |*sel| {
|
||||
try Editor.move_cursor_left(root, &sel.end, ed.metrics);
|
||||
cursel.cursor = sel.end;
|
||||
|
||||
if (sel.begin.col == sel.end.col and sel.begin.row == sel.end.row) {
|
||||
try sel.begin.move_right(root, ed.metrics);
|
||||
try Editor.move_cursor_left(root, &sel.end, ed.metrics);
|
||||
cursel.cursor = sel.end;
|
||||
}
|
||||
}
|
||||
|
||||
cursel.check_selection(root, ed.metrics);
|
||||
};
|
||||
ed.clamp();
|
||||
}
|
||||
pub const select_left_helix_meta: Meta = .{ .description = "Select left" };
|
||||
|
||||
pub fn select_to_char_right_helix(_: *void, ctx: Ctx) Result {
|
||||
const mv = tui.mainview() orelse return;
|
||||
const ed = mv.get_active_editor() orelse return;
|
||||
const root = try ed.buf_root();
|
||||
|
||||
for (ed.cursels.items) |*cursel_| if (cursel_.*) |*cursel| {
|
||||
const sel = try cursel.enable_selection(root, ed.metrics);
|
||||
try Editor.move_cursor_to_char_right(root, &sel.end, ctx, ed.metrics);
|
||||
try Editor.move_cursor_right(root, &sel.end, ed.metrics);
|
||||
cursel.cursor = sel.end;
|
||||
cursel.check_selection(root, ed.metrics);
|
||||
};
|
||||
ed.clamp();
|
||||
}
|
||||
pub const select_to_char_right_helix_meta: Meta = .{ .description = "Move to char right" };
|
||||
};
|
||||
|
||||
fn move_cursor_word_left_helix(root: Buffer.Root, cursor: *Cursor, metrics: Buffer.Metrics) error{Stop}!void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue