feat: make goto in flow select mode select to line

This commit is contained in:
CJ van den Berg 2025-12-16 15:09:58 +01:00
parent a9ee5321ac
commit 0dcf63bd38
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 32 additions and 4 deletions

View file

@ -263,6 +263,7 @@
"inherit": "normal",
"cursor": "block",
"press": [
["ctrl+g", "goto", "select"],
["left", "select_left"],
["right", "select_right"],
["ctrl+left", "select_word_left"],

View file

@ -3432,6 +3432,13 @@ pub const Editor = struct {
}
pub const move_word_right_end_vim_meta: Meta = .{ .description = "Move cursor right by end of word (vim)", .arguments = &.{.integer} };
fn move_cursor_to_line(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
var line: usize = 0;
if (!(ctx.args.match(.{tp.extract(&line)}) catch return error.Stop))
return error.Stop;
try cursor.move_to(root, line -| 1, cursor.col, metrics);
}
fn move_cursor_to_char_left(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void {
var egc: []const u8 = undefined;
if (!(ctx.args.match(.{tp.extract(&egc)}) catch return error.Stop))
@ -5740,6 +5747,15 @@ pub const Editor = struct {
}
pub const goto_line_meta: Meta = .{ .arguments = &.{.integer} };
pub fn select_to_line(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
const root = self.buf_root() catch return;
self.with_selections_const_arg(root, move_cursor_to_line, ctx) catch {};
self.clamp();
try self.send_editor_jump_destination();
}
pub const select_to_line_meta: Meta = .{ .arguments = &.{.integer} };
pub fn goto_line_vim(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
var line: usize = 0;

View file

@ -1,4 +1,5 @@
const fmt = @import("std").fmt;
const cbor = @import("cbor");
const command = @import("command");
const tui = @import("../../tui.zig");
@ -83,10 +84,20 @@ pub const preview = goto;
pub const apply = goto;
pub const cancel = goto;
fn goto(self: *Type, _: command.Context) void {
send_goto(if (self.input) |input| input.cursor else self.start.cursor);
const Mode = enum {
goto,
select,
};
fn goto(self: *Type, ctx: command.Context) void {
var mode: Mode = .goto;
_ = ctx.args.match(.{cbor.extract(&mode)}) catch {};
send_goto(mode, if (self.input) |input| input.cursor else self.start.cursor);
}
fn send_goto(cursor: Cursor) void {
command.executeName("goto_line_and_column", command.fmt(.{ cursor.row, cursor.col })) catch {};
fn send_goto(mode: Mode, cursor: Cursor) void {
switch (mode) {
.goto => command.executeName("goto_line_and_column", command.fmt(.{ cursor.row, cursor.col })) catch {},
.select => command.executeName("select_to_line", command.fmt(.{cursor.row})) catch {},
}
}