From 0dcf63bd383f8dbc7da0e11198877019e49a0169 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 16 Dec 2025 15:09:58 +0100 Subject: [PATCH] feat: make goto in flow select mode select to line --- src/keybind/builtin/flow.json | 1 + src/tui/editor.zig | 16 ++++++++++++++++ src/tui/mode/mini/goto.zig | 19 +++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/keybind/builtin/flow.json b/src/keybind/builtin/flow.json index fa63655..0287d9b 100644 --- a/src/keybind/builtin/flow.json +++ b/src/keybind/builtin/flow.json @@ -263,6 +263,7 @@ "inherit": "normal", "cursor": "block", "press": [ + ["ctrl+g", "goto", "select"], ["left", "select_left"], ["right", "select_right"], ["ctrl+left", "select_word_left"], diff --git a/src/tui/editor.zig b/src/tui/editor.zig index d2166be..9de9e4b 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -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; diff --git a/src/tui/mode/mini/goto.zig b/src/tui/mode/mini/goto.zig index 963ec7f..58ed800 100644 --- a/src/tui/mode/mini/goto.zig +++ b/src/tui/mode/mini/goto.zig @@ -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 {}, + } }