╭ changed ─────────────╮ │src/ui/Repo/Header.zig│ ╰──────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 94 const commits_link = try std.fmt.allocPrint(aa, "a:{s}", .{try commits_route.urlAlloc(session.page_arena)}); │ │ 95 const settings_link = try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}/settings", .{ data.owner_name, data.name });│ │ 96 const auth_link = try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}/auth", .{ data.owner_name, data.name }); │ │ 97 + │ │ 98 + // the tab matching the current page is focused initially; matching by │ │ 99 + // link (rather than position) keeps this robust to tab changes. │ │100 + const current_link: []const u8 = switch (session.data.current_page) { │ │101 + .repo_commits => commits_link, │ │102 + .repo_settings => settings_link, │ │103 + .repo_auth => auth_link, │ │104 + else => files_link, │ │105 + }; │ │106 + var selected_tab: ?usize = null; │ │107 │ │108 // files tab │ │109 { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮ │112 text_box.getFocus().focusable = true; │ │113 text_box.getFocus().kind = .{ .custom = files_link }; │ │114 try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │115 + if (std.mem.eql(u8, files_link, current_link)) selected_tab = text_box.getFocus().id;│ │116 try box.children.put(allocator, text_box.getFocus().id, .{ │ │117 .widget = .{ .text_box = text_box }, │ │118 .rect = null, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │127 text_box.getFocus().focusable = true; │ │128 text_box.getFocus().kind = .{ .custom = commits_link }; │ │129 try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │130 + if (std.mem.eql(u8, commits_link, current_link)) selected_tab = text_box.getFocus().id;│ │131 try box.children.put(allocator, text_box.getFocus().id, .{ │ │132 .widget = .{ .text_box = text_box }, │ │133 .rect = null, │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │153 text_box.getFocus().focusable = true; │ │154 text_box.getFocus().kind = .{ .custom = settings_link }; │ │155 try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │156 + if (std.mem.eql(u8, settings_link, current_link)) selected_tab = text_box.getFocus().id;│ │157 try box.children.put(allocator, text_box.getFocus().id, .{ │ │158 .widget = .{ .text_box = text_box }, │ │159 .rect = null, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │168 errdefer auth_tab.deinit(allocator); │ │169 auth_tab.text_box.getFocus().kind = .{ .custom = auth_link }; │ │170 try tab_ids.put(allocator, auth_tab.getFocus().id, {}); │ │171 + if (std.mem.eql(u8, auth_link, current_link)) selected_tab = auth_tab.getFocus().id;│ │172 try box.children.put(allocator, auth_tab.getFocus().id, .{ │ │173 .widget = .{ .auth_tab = auth_tab }, │ │174 .rect = null, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │192 } │ │193 │ │194 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; │ │181 - // open on the tab named by the current route │ │182 - self.getFocus().child_id = self.tab_ids.keys()[ │ │183 - switch (session.data.current_page) { │ │184 - .repo_commits => 1, │ │185 - .repo_settings => 2, │ │186 - .repo_auth => 3, │ │187 - else => 0, │ │188 - } │ │189 - ]; │ │195 + self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0];│ │196 return self; │ │197 } │ │198 │ ╰───────────────────────────────────────────────────────────────────────────────────╯