fix: always call reload_file when re-openning an hidden non-ephemeral buffer

This is less confusing than just restoring the buffer as is. If the file has
changed on disk the usual expectation is to load the new contents on re-opening
the file.

closes #339
This commit is contained in:
CJ van den Berg 2025-10-28 16:34:44 +01:00
parent 45669cad31
commit 02deaab3a7
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -41,7 +41,11 @@ pub fn delete_buffer(self: *Self, buffer_: *Buffer) void {
}
pub fn open_file(self: *Self, file_path: []const u8) Buffer.LoadFromFileError!*Buffer {
const buffer = if (self.get_buffer(file_path)) |buffer| buffer else blk: {
const buffer = if (self.get_buffer(file_path)) |buffer| blk: {
if (!buffer.ephemeral and buffer.hidden)
try buffer.refresh_from_file();
break :blk buffer;
} else blk: {
var buffer = try Buffer.create(self.allocator);
errdefer buffer.deinit();
try buffer.load_from_file_and_update(file_path);