feat(buffers): add support for buffer metadata

This commit is contained in:
CJ van den Berg 2025-01-29 20:43:31 +01:00
parent 917462a6e3
commit ecca2d0b4c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -41,6 +41,7 @@ last_save_eol_mode: EolMode = .lf,
file_utf8_sanitized: bool = false, file_utf8_sanitized: bool = false,
hidden: bool = false, hidden: bool = false,
ephemeral: bool = false, ephemeral: bool = false,
meta: ?[]const u8 = null,
undo_history: ?*UndoNode = null, undo_history: ?*UndoNode = null,
redo_history: ?*UndoNode = null, redo_history: ?*UndoNode = null,
@ -1064,12 +1065,23 @@ pub fn create(allocator: Allocator) error{OutOfMemory}!*Self {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
if (self.meta) |buf| self.external_allocator.free(buf);
if (self.file_buf) |buf| self.external_allocator.free(buf); if (self.file_buf) |buf| self.external_allocator.free(buf);
if (self.leaves_buf) |buf| self.external_allocator.free(buf); if (self.leaves_buf) |buf| self.external_allocator.free(buf);
self.arena.deinit(); self.arena.deinit();
self.external_allocator.destroy(self); self.external_allocator.destroy(self);
} }
pub fn set_meta(self: *Self, meta_: []const u8) error{OutOfMemory}!void {
const meta = try self.external_allocator.dupe(u8, meta_);
if (self.meta) |buf| self.external_allocator.free(buf);
self.meta = meta;
}
pub fn get_meta(self: *Self) ?[]const u8 {
return self.meta;
}
pub fn update_last_used_time(self: *Self) void { pub fn update_last_used_time(self: *Self) void {
self.utime = std.time.milliTimestamp(); self.utime = std.time.milliTimestamp();
} }