From 4765f47dd0e029e9cba3c7b9071585ac81a3d064 Mon Sep 17 00:00:00 2001 From: Robert Burnett Date: Mon, 12 May 2025 11:38:41 -0500 Subject: [PATCH] begin supporting global marks --- src/tui/editor.zig | 24 ++++++++++++++++++++++++ src/tui/tui.zig | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index db9ebf4..96ffb0c 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -5130,6 +5130,30 @@ pub const Editor = struct { std.mem.sort(Diagnostic, self.diagnostics.items, {}, less_fn); } + pub fn goto_global_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 location = tui.get_global_marks()[mark_id] orelse return error.UndefinedGlobalMark; + _ = location; + + //TODO: figure out how to goto location in another file + } + pub const goto_global_mark_meta: Meta = .{ .arguments = &.{.integer} }; + + pub fn set_global_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 buf = self.buffer orelse return error.Stop; + var location: tui.GlobalMarkLocation = .{ .row = primary.cursor.row, .col = primary.cursor.col }; + std.mem.copyForwards(u8, &location.filepath, buf.file_path); + tui.get_global_marks()[mark_id] = location; + } + pub const set_global_mark_meta: Meta = .{ .arguments = &.{.integer} }; + pub fn goto_mark(self: *Self, ctx: Context) Result { try self.send_editor_jump_source(); var mark_id: u8 = 0; diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 7998654..cc6ecad 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -20,6 +20,12 @@ const MainView = @import("mainview.zig"); const Allocator = std.mem.Allocator; +pub const GlobalMarkLocation = struct { + row: usize, + col: usize, + filepath: [512]u8 = .{0} ** 512, +}; + allocator: Allocator, rdr_: renderer, config_: @import("config"), @@ -62,6 +68,7 @@ fontfaces_: std.ArrayListUnmanaged([]const u8) = .{}, enable_mouse_idle_timer: bool = false, query_cache_: *syntax.QueryCache, frames_rendered_: usize = 0, +global_marks: [256]?GlobalMarkLocation = .{null} ** 256, const keepalive = std.time.us_per_day * 365; // one year const idle_frames = 0; @@ -1091,6 +1098,10 @@ fn current() *Self { return instance_ orelse @panic("tui call out of context"); } +pub fn get_global_marks() *[256]?GlobalMarkLocation { + return ¤t().global_marks; +} + pub fn rdr() *renderer { return ¤t().rdr_; }