began support vim mark system

This commit is contained in:
Robert Burnett 2025-05-12 09:39:51 -05:00 committed by CJ van den Berg
parent da95070616
commit d88b15ce04
3 changed files with 39 additions and 1 deletions

View file

@ -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;

View file

@ -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": {

View file

@ -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;