feat(buffers): add support for ephemeral buffers

Ephemeral buffers are not hidden and kept when closed. Ephemeral buffers
can be turned into regular buffers by saving them with save_as.
This commit is contained in:
CJ van den Berg 2025-01-27 18:59:13 +01:00
parent 8062923068
commit 939537ed84
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
7 changed files with 92 additions and 18 deletions

View file

@ -40,6 +40,7 @@ file_eol_mode: EolMode = .lf,
last_save_eol_mode: EolMode = .lf,
file_utf8_sanitized: bool = false,
hidden: bool = false,
ephemeral: bool = false,
undo_history: ?*UndoNode = null,
redo_history: ?*UndoNode = null,
@ -1279,6 +1280,7 @@ pub const StoreToFileError = error{
NotDir,
NotOpenForWriting,
OperationAborted,
OutOfMemory,
PathAlreadyExists,
PipeBusy,
ProcessFdQuotaExceeded,
@ -1315,12 +1317,24 @@ pub fn store_to_file_and_clean(self: *Self, file_path: []const u8) StoreToFileEr
self.last_save_eol_mode = self.file_eol_mode;
self.file_exists = true;
self.file_utf8_sanitized = false;
if (self.ephemeral) {
self.ephemeral = false;
self.file_path = try self.allocator.dupe(u8, file_path);
}
}
pub fn mark_clean(self: *Self) void {
self.last_save = self.root;
}
pub fn is_hidden(self: *const Self) bool {
return self.hidden;
}
pub fn is_ephemeral(self: *const Self) bool {
return self.ephemeral;
}
pub fn is_dirty(self: *const Self) bool {
return if (!self.file_exists)
self.root.length() > 0