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/keybind/builtin/helix.json b/src/keybind/builtin/helix.json index 915fb57..c6223b9 100644 --- a/src/keybind/builtin/helix.json +++ b/src/keybind/builtin/helix.json @@ -356,7 +356,7 @@ ["t", "move_to_char", "extend_till_char_right_helix"], ["f", "move_to_char", "extend_to_char_right_helix"], - ["G", "goto_line"], + ["G", "select_to_line"], ["I", ["enter_mode", "insert"], ["smart_move_begin"]], ["A", ["enter_mode", "insert"], ["move_end"]], @@ -413,8 +413,8 @@ ["end", "extend_to_line_end"], ["v", "enter_mode", "normal"], - ["g g", "goto_line_vim"], - ["g e", "move_buffer_end"], + ["g g", "select_to_line_vim"], + ["g e", "select_buffer_end"], ["g f", "goto_file"], ["g h", "move_begin"], ["g l", "select_end"], diff --git a/src/tui/editor.zig b/src/tui/editor.zig index d2166be..4593e41 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -3432,6 +3432,19 @@ 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_line_vim(root: Buffer.Root, cursor: *Cursor, ctx: Context, metrics: Buffer.Metrics) error{Stop}!void { + var line: usize = 0; + _ = ctx.args.match(.{tp.extract(&line)}) catch false; + 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 +5753,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; @@ -5752,6 +5774,15 @@ pub const Editor = struct { } pub const goto_line_vim_meta: Meta = .{ .arguments = &.{.integer} }; + pub fn select_to_line_vim(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_vim, ctx) catch {}; + self.clamp(); + try self.send_editor_jump_destination(); + } + pub const select_to_line_vim_meta: Meta = .{ .arguments = &.{.integer} }; + pub fn goto_column(self: *Self, ctx: Context) Result { const root = self.buf_root() catch return; const primary = self.get_primary(); diff --git a/src/tui/editor_gutter.zig b/src/tui/editor_gutter.zig index 83ad8b4..be7fc83 100644 --- a/src/tui/editor_gutter.zig +++ b/src/tui/editor_gutter.zig @@ -446,7 +446,7 @@ fn print_digits(self: *Self, n_: anytype, style_: DigitStyle) !void { if (n == 0) break; } std.mem.reverse([]const u8, digits.items); - try self.plane.cursor_move_yx(@intCast(self.plane.cursor_y()), @intCast(self.width - digits.items.len - 1)); + try self.plane.cursor_move_yx(@intCast(self.plane.cursor_y()), @intCast(self.width -| digits.items.len -| 1)); for (digits.items) |digit| _ = try self.plane.putstr(digit); } diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 59877cd..ecc5878 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -1496,6 +1496,8 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result const text = editor.get_selection(sel, self.allocator) catch return self.clear_auto_find(editor); if (text.len == 0) return self.clear_auto_find(editor); + if (text.len == 1 and (text[0] == ' ')) + return self.clear_auto_find(editor); if (!self.is_last_match_text(text)) tp.self_pid().send(.{ "cmd", "find_query", .{ text, "auto_find" } }) catch return; } 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 {}, + } }