From 0cba416ec4116083e0aac5cf13dee68f1dc8b183 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 27 Nov 2025 18:23:23 +0100 Subject: [PATCH] refactor: move goto_line_vim into mode specific commands files --- src/tui/editor.zig | 12 ------------ src/tui/mode/helix.zig | 12 ++++++++++++ src/tui/mode/vim.zig | 13 +++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 7a9e7ac..35b8c14 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -5460,18 +5460,6 @@ pub const Editor = struct { } pub const goto_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; - _ = ctx.args.match(.{tp.extract(&line)}) catch false; - const root = self.buf_root() catch return; - const primary = self.get_primary(); - try primary.cursor.move_to(root, @intCast(if (line < 1) 0 else line - 1), primary.cursor.col, self.metrics); - self.clamp(); - try self.send_editor_jump_destination(); - } - pub const goto_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/mode/helix.zig b/src/tui/mode/helix.zig index 849700d..57e3796 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -522,6 +522,18 @@ const cmds_ = struct { ed.need_render(); } pub const replace_with_character_helix_meta: Meta = .{ .description = "Replace with character" }; + + pub fn goto_line_helix(self: *Self, ctx: Context) Result { + try self.send_editor_jump_source(); + var line: usize = 0; + _ = ctx.args.match(.{tp.extract(&line)}) catch false; + const root = self.buf_root() catch return; + const primary = self.get_primary(); + try primary.cursor.move_to(root, @intCast(if (line < 1) 0 else line - 1), primary.cursor.col, self.metrics); + self.clamp(); + try self.send_editor_jump_destination(); + } + pub const goto_line_helix_meta: Meta = .{ .arguments = &.{.integer} }; }; fn get_context() ?struct { *MainView, *Editor } { diff --git a/src/tui/mode/vim.zig b/src/tui/mode/vim.zig index d59b858..2236134 100644 --- a/src/tui/mode/vim.zig +++ b/src/tui/mode/vim.zig @@ -1,5 +1,6 @@ const std = @import("std"); const command = @import("command"); +const tp = @import("thespian"); const cmd = command.executeName; const tui = @import("../tui.zig"); @@ -209,6 +210,18 @@ const cmds_ = struct { self.clamp(); } pub const move_down_vim_meta: Meta = .{ .description = "Move cursor down (vim)", .arguments = &.{.integer} }; + + pub fn goto_line_vim(self: *Self, ctx: Context) Result { + try self.send_editor_jump_source(); + var line: usize = 0; + _ = ctx.args.match(.{tp.extract(&line)}) catch false; + const root = self.buf_root() catch return; + const primary = self.get_primary(); + try primary.cursor.move_to(root, @intCast(if (line < 1) 0 else line - 1), primary.cursor.col, self.metrics); + self.clamp(); + try self.send_editor_jump_destination(); + } + pub const goto_line_vim_meta: Meta = .{ .arguments = &.{.integer} }; }; fn is_eol_right_vim(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics) bool {