╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ─────────────╮ │src/ui/User/Header.zig│ ╰──────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │71 const settings_link = try std.fmt.allocPrint(aa, "a:/user/{s}/settings", .{data.name}); │ │72 const auth_link = try std.fmt.allocPrint(aa, "a:/user/{s}/auth", .{data.name}); │ │73 │ │74 + // the tab matching the current page is focused initially; matching by │ │75 + // link (rather than position) keeps this robust to tab changes. │ │76 + const current_link: []const u8 = switch (session.data.current_page) { │ │77 + .user_settings => settings_link, │ │78 + .user_auth => auth_link, │ │79 + else => repos_link, │ │80 + }; │ │81 + var selected_tab: ?usize = null; │ │82 + │ │83 // repos tab │ │84 { │ │85 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "repos", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none });│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │87 text_box.getFocus().focusable = true; │ │88 text_box.getFocus().kind = .{ .custom = repos_link }; │ │89 try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │90 + if (std.mem.eql(u8, repos_link, current_link)) selected_tab = text_box.getFocus().id;│ │91 try box.children.put(allocator, text_box.getFocus().id, .{ │ │92 .widget = .{ .text_box = text_box }, │ │93 .rect = null, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │113 text_box.getFocus().focusable = true; │ │114 text_box.getFocus().kind = .{ .custom = settings_link }; │ │115 try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │116 + if (std.mem.eql(u8, settings_link, current_link)) selected_tab = text_box.getFocus().id;│ │117 try box.children.put(allocator, text_box.getFocus().id, .{ │ │118 .widget = .{ .text_box = text_box }, │ │119 .rect = null, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────╮ │128 errdefer auth_tab.deinit(allocator); │ │129 auth_tab.text_box.getFocus().kind = .{ .custom = auth_link }; │ │130 try tab_ids.put(allocator, auth_tab.getFocus().id, {}); │ │131 + if (std.mem.eql(u8, auth_link, current_link)) selected_tab = auth_tab.getFocus().id;│ │132 try box.children.put(allocator, auth_tab.getFocus().id, .{ │ │133 .widget = .{ .auth_tab = auth_tab }, │ │134 .rect = null, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │152 } │ │153 │ │154 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; │ │143 - // open on the tab named by the current route │ │144 - self.getFocus().child_id = self.tab_ids.keys()[ │ │145 - switch (session.data.current_page) { │ │146 - .user_settings => 1, │ │147 - .user_auth => 2, │ │148 - else => 0, │ │149 - } │ │150 - ]; │ │155 + self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0];│ │156 return self; │ │157 } │ │158 │ ╰───────────────────────────────────────────────────────────────────────────────────╯