From d88b15ce040fd6edd04b986eafa5eff9907fe657 Mon Sep 17 00:00:00 2001 From: Robert Burnett Date: Mon, 12 May 2025 09:39:51 -0500 Subject: [PATCH] began support vim mark system --- src/buffer/Buffer.zig | 7 +++++++ src/keybind/builtin/vim.json | 5 ++++- src/tui/editor.zig | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index 76ca303..e7859ce 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -27,6 +27,11 @@ pub const Metrics = struct { pub const egc_last_func = *const fn (self: Metrics, egcs: []const u8) []const u8; }; +pub const MarkLocation = struct { + row: usize, + col: usize, +}; + arena: std.heap.ArenaAllocator, allocator: Allocator, external_allocator: Allocator, @@ -54,6 +59,8 @@ file_type_name: ?[]const u8 = null, file_type_icon: ?[]const u8 = null, file_type_color: ?u24 = null, +marks: [256]?MarkLocation = .{null} ** 256, + pub const EolMode = enum { lf, crlf }; pub const EolModeTag = @typeInfo(EolMode).@"enum".tag_type; diff --git a/src/keybind/builtin/vim.json b/src/keybind/builtin/vim.json index 8f208e3..b72f392 100644 --- a/src/keybind/builtin/vim.json +++ b/src/keybind/builtin/vim.json @@ -106,7 +106,10 @@ ["6", "add_integer_argument_digit", 6], ["7", "add_integer_argument_digit", 7], ["8", "add_integer_argument_digit", 8], - ["9", "add_integer_argument_digit", 9] + ["9", "add_integer_argument_digit", 9], + + ["ma", "set_mark", 55], + ["'a", "goto_mark", 55] ] }, "visual": { diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 2509bad..db9ebf4 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -5130,6 +5130,34 @@ pub const Editor = struct { std.mem.sort(Diagnostic, self.diagnostics.items, {}, less_fn); } + pub fn goto_mark(self: *Self, ctx: Context) Result { + try self.send_editor_jump_source(); + var mark_id: u8 = 0; + if (!try ctx.args.match(.{tp.extract(&mark_id)})) + return error.InvalidGotoLineArgument; + const buf = self.buffer orelse return error.Stop; + const location = buf.marks[mark_id] orelse return error.UndefinedMark; + + const root = self.buf_root() catch return; + self.cancel_all_selections(); + const primary = self.get_primary(); + try primary.cursor.move_to(root, location.row, location.col, self.metrics); + self.clamp(); + try self.send_editor_jump_destination(); + } + pub const goto_mark_meta: Meta = .{ .arguments = &.{.integer} }; + + pub fn set_mark(self: *Self, ctx: Context) Result { + var mark_id: u8 = 0; + if (!try ctx.args.match(.{tp.extract(&mark_id)})) + return error.InvalidGotoLineArgument; + const primary = self.get_primary(); + const location: Buffer.MarkLocation = .{ .row = primary.cursor.row, .col = primary.cursor.col }; + var buf = self.buffer orelse return error.Stop; + buf.marks[mark_id] = location; + } + pub const set_mark_meta: Meta = .{ .arguments = &.{.integer} }; + pub fn goto_line(self: *Self, ctx: Context) Result { try self.send_editor_jump_source(); var line: usize = 0;