fix: restart with no open file should return to home screen

This commit is contained in:
CJ van den Berg 2025-08-08 13:32:57 +02:00
parent dd2601b627
commit a98d4e02a7
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -1293,9 +1293,12 @@ pub fn write_restore_info(self: *Self) void {
var meta = std.ArrayListUnmanaged(u8).empty;
const writer = meta.writer(a);
const editor = self.get_active_editor() orelse return;
cbor.writeValue(writer, editor.file_path) catch return;
editor.update_meta();
if (self.get_active_editor()) |editor| {
cbor.writeValue(writer, editor.file_path) catch return;
editor.update_meta();
} else {
cbor.writeValue(writer, null) catch return;
}
const buffer_manager = tui.get_buffer_manager() orelse @panic("tabs no buffer manager");
buffer_manager.write_state(writer) catch return;
@ -1317,11 +1320,15 @@ fn read_restore_info(self: *Self) !void {
var iter: []const u8 = buf[0..size];
tp.trace(tp.channel.debug, .{ "mainview", "extract" });
var editor_file_path: []const u8 = undefined;
var editor_file_path: ?[]const u8 = undefined;
if (!try cbor.matchValue(&iter, cbor.extract(&editor_file_path))) return error.Stop;
try self.buffer_manager.extract_state(&iter);
try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = editor_file_path } });
if (editor_file_path) |file_path| {
try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } });
} else {
try tp.self_pid().send(.{ "cmd", "close_file" });
}
}
fn get_next_mru_buffer(self: *Self) ?[]const u8 {