~jamii/focus

7ab6eceafbcc98d68fb5bb6b6a2a2d8e29d9c0cd — Jamie Brandon 11 months ago 9b5cf21
Avoid touching undo stack on first load
1 files changed, 8 insertions(+), 7 deletions(-)

M lib/focus/buffer.zig
M lib/focus/buffer.zig => lib/focus/buffer.zig +8 -7
@@ 98,10 98,8 @@ pub const Buffer = struct {
                .mtime = 0,
            },
        };
        self.load();
        // don't want the load on the undo stack
        for (self.doing.items) |edit| edit.deinit(self.app.allocator);
        self.doing.shrink(0);
        self.load(.Init);
        self.undos.resize(0) catch oom();
        return self;
    }



@@ 162,9 160,12 @@ pub const Buffer = struct {
        };
    }

    fn load(self: *Buffer) void {
    fn load(self: *Buffer, kind: enum { Init, Refresh }) void {
        if (self.tryLoad()) |result| {
            self.replace(result.bytes);
            switch (kind) {
                .Init => self.rawReplace(result.bytes),
                .Refresh => self.replace(result.bytes),
            }
            self.source.File.mtime = result.mtime;
        } else |err| {
            const message = format(self.app.frame_allocator, "{} while loading {s}", .{ err, self.getFilename() });


@@ 190,7 191,7 @@ pub const Buffer = struct {
                defer file.close();
                const stat = file.stat() catch |err| panic("{} while refreshing {s}", .{ err, file_source.absolute_filename });
                if (stat.mtime != file_source.mtime) {
                    self.load();
                    self.load(.Refresh);
                }
            },
        }