╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1726 1727 const header_index: usize = 0; 1728 const stack_index: usize = 1; 1729 // indices within the stack, 1:1 with the header tabs. 1730 const status_count = @typeInfo(Status).@"enum".field_names.len; 1731 const labels_view_index: usize = status_count; 1732 // the new-thread form, or the edit, comment, or resolve form when the page was 1733 // loaded at one of their urls. 1734 const form_view_index: usize = labels_view_index + 1; 1735 // the conflicts split; the tab and stack child exist only when the repo 1736 // has conflicted threads. 1737 const drafts_view_index: usize = form_view_index + 1; 1738 const conflict_view_index: usize = drafts_view_index + @intFromBool(supports_drafts); 1739 const view_count: usize = conflict_view_index + @intFromBool(supports_conflicts); 1740 // indices within a split (the horizontal box inside the stack). 1741 const list_index: usize = 0; 1742 const detail_index: usize = 1; 1743 const list_max_width: usize = 35; 1744 const detail_min_width: usize = 40; 1745 1746 pub fn viewIndex(view: ViewKind) usize { 1747 const name = @tagName(view); 1748 if (std.mem.eql(u8, name, "labels")) return labels_view_index; 1749 if (std.mem.eql(u8, name, "new") or std.mem.eql(u8, name, "edit") or std.mem.eql(u8, name, "publish") or std.mem.eql(u8, name, "merge") or std.mem.eql(u8, name, "new_comment") or std.mem.eql(u8, name, "edit_comment") or std.mem.eql(u8, name, "remove") or std.mem.eql(u8, name, "resolve")) return form_view_index; 1750 if (std.mem.eql(u8, name, "conflicts")) return conflict_view_index; 1751 if (std.mem.eql(u8, name, "drafts")) return drafts_view_index; 1752 if (std.mem.eql(u8, name, "description")) unreachable; 1753 inline for (@typeInfo(Status).@"enum".field_names, 0..) |status_name, index| { 1754 if (std.mem.eql(u8, name, status_name)) return index; 1755 } 1756 unreachable; 1757 } 1758 1759 const Confirmation = enum { remove, publish, merge }; 1760 1761 fn confirmation(view: ViewKind) ?Confirmation { 1762 if (view == .remove) return .remove; 1763 if (supports_drafts and std.mem.eql(u8, @tagName(view), "publish")) return .publish; 1764 if (supports_merge and std.mem.eql(u8, @tagName(view), "merge")) return .merge; 1765 return null; 1766 } 1767 1768 // the status a status split lists; the conflicts split has none (its 1769 // threads carry their own). 1770 fn splitStatus(index: usize) Status { 1771 return @fromBackingInt(@intCast(index)); 1772 } 1773 1774 fn entryConflicted(entry: Entry) bool { 1775 return if (supports_conflicts) entry.conflicted else false; 1776 } 1777 1778 fn entryStatus(entry: Entry) Status { 1779 if (comptime has_status) return Data.statusKind(entry.record.event); 1780 return @fromBackingInt(@intCast(0)); 1781 } 1782 1783 fn entryDraft(entry: Entry) bool { 1784 return if (supports_drafts) entry.draft else false; 1785 } 1786 1787 fn listRoute(identity: []const u8, status: Status, label: []const u8, selected: []const u8) ?ui.RoutablePage { 1788 return Data.listRoute(identity, status, label, selected); 1789 } 1790 1791 fn draftsRoute(identity: []const u8) ?ui.RoutablePage { 1792 return if (supports_drafts) Data.draftsRoute(identity) else null; 1793 } 1794 1795 fn publishRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 1796 return if (supports_drafts) Data.publishRoute(identity, selected) else null; 1797 } 1798 1799 fn mergeRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 1800 return if (supports_merge) Data.mergeRoute(identity, selected) else null; 1801 } 1802 1803 fn conflictsRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 1804 return if (supports_conflicts) Data.conflictsRoute(identity, selected) else null; 1805 } 1806 1807 fn resolveRoute(identity: []const u8, selected: []const u8, picks: []const u8) ?ui.RoutablePage { 1808 return if (supports_conflicts) Data.resolveRoute(identity, selected, picks) else null; 1809 } 1810 1811 // a list link keeps the filters the page carries: the label, and the 1812 // search query and url-encoded assignee when set 1813 fn listLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: Status, label: []const u8, id: []const u8, search: []const u8, assignee: []const u8) ![]const u8 { 1814 var route = listRoute(identity, status, label, id) orelse return error.RouteTooLong; 1815 if (search.len != 0) route = route.withSearch(search) orelse return error.RouteTooLong; 1816 if (assignee.len != 0) route = route.withEncodedAssignee(assignee) orelse return error.RouteTooLong; 1817 return page_arena.allocator().print("a:{s}", .{try route.toUrl(page_arena)}); 1818 } 1819 1820 fn rowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, id: []const u8) ![]const u8 { 1821 const selected = std.mem.eql(u8, id, data.selected_id); 1822 const route = (if (selected and data.description_page) 1823 ui.RoutablePage.repoThreadDescriptionRoute(kind, data.identity, id) 1824 else if (selected) 1825 if (data.comment_page) |page| 1826 ui.RoutablePage.repoThreadCommentRoute(kind, data.identity, id, &page.selected.id, page.replies.start) 1827 else 1828 ui.RoutablePage.repoThreadCommentsRoute(kind, data.identity, id, data.comments_start) 1829 else 1830 ui.RoutablePage.repoThreadCommentsRoute(kind, data.identity, id, 0)) orelse return error.RouteTooLong; 1831 return page_arena.allocator().print("ai:{s}", .{try route.toUrl(page_arena)}); 1832 } 1833 1834 fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?Status, drafts: bool, id: []const u8) ![]const u8 { 1835 if (supports_conflicts and status_maybe == null and !drafts) { 1836 const route = conflictsRoute(data.identity, id) orelse return error.RouteTooLong; 1837 return page_arena.allocator().print("a:{s}", .{try route.toUrl(page_arena)}); 1838 } 1839 if (drafts and id.len == 0) { 1840 const route = draftsRoute(data.identity) orelse return error.RouteTooLong; 1841 return page_arena.allocator().print("a:{s}", .{try route.toUrl(page_arena)}); 1842 } 1843 return listLink(page_arena, data.identity, status_maybe orelse @fromBackingInt(@intCast(0)), data.label, id, data.search orelse "", assigneeFilter(data)); 1844 } 1845 1846 fn labelLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: Status, label: []const u8, search: []const u8, assignee: []const u8) ![]const u8 { 1847 const encoded = try ui.urlEncodeRef(page_arena.allocator(), label); 1848 return listLink(page_arena, identity, status, encoded, "", search, assignee); 1849 } 1850 1851 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !This { 1852 var outer = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 1853 errdefer outer.deinit(allocator); 1854 1855 // the tabs at the top. 1856 { 1857 var hdr = try Data.initHeader(allocator, session, data); 1858 errdefer hdr.deinit(allocator); 1859 try outer.children.put(allocator, hdr.getFocus().id, .{ .widget = @unionInit(Widget, Data.header_widget_name, hdr), .rect = null, .min_size = null }); 1860 } 1861 1862 // the stack enters `outer` before its children enter it, so an error 1863 // frees each child exactly once. 1864 { 1865 var stack = try wgt.Stack(Widget).init(allocator); 1866 errdefer stack.deinit(allocator); 1867 try outer.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 1868 } 1869 const stack = &outer.children.values()[stack_index].widget.stack; 1870 1871 inline for (@typeInfo(Status).@"enum".field_values) |value| { 1872 var split = try initSplit(allocator, session, data, @fromBackingInt(@intCast(value)), false); 1873 errdefer split.deinit(allocator); 1874 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 1875 } 1876 1877 // the labels view 1878 { 1879 var tf = try WordFlow.init(allocator); 1880 errdefer tf.deinit(allocator); 1881 var items: std.ArrayList(WordFlow.Item) = .empty; 1882 defer items.deinit(allocator); 1883 // when filtered, the first item clears the filter 1884 if (data.label.len != 0) 1885 try items.append(allocator, .{ .text = "✕", .link = try listLink(session.page_arena, data.identity, @fromBackingInt(@intCast(0)), "", "", data.search orelse "", assigneeFilter(data)) }); 1886 for (data.labels) |label| 1887 try items.append(allocator, .{ .text = label, .link = try labelLink(session.page_arena, data.identity, @fromBackingInt(@intCast(0)), label, data.search orelse "", assigneeFilter(data)) }); 1888 try tf.setItems(allocator, items.items); 1889 try stack.children.put(allocator, tf.getFocus().id, .{ .word_flow = tf }); 1890 } 1891 1892 // the new-thread form, or — on an edit, comment, or resolve url — that form in 1893 // its place, prefilled with the selected thread's content. a viewer 1894 // who can't write in this tab gets the unauthorized view instead, 1895 // while local mode always writes. 1896 if (session.data.host_kind == .local or data.viewer != null) { 1897 if (confirmation(data.view)) |confirmation_kind| { 1898 const aa = session.page_arena.allocator(); 1899 const route = switch (confirmation_kind) { 1900 .remove => ui.RoutablePage.repoThreadRemoveRoute(kind, data.identity, data.selected_id, data.comment_id), 1901 .publish => publishRoute(data.identity, data.selected_id), 1902 .merge => mergeRoute(data.identity, data.selected_id), 1903 } orelse return error.RouteTooLong; 1904 const page_url = try route.toUrl(session.page_arena); 1905 const action = try aa.print("form:{s}", .{page_url}); 1906 const event_name = if (data.comment_id.len == 0) thread_name else "comment"; 1907 var label_buf: ["remove ".len + @max(thread_name.len, "comment".len)]u8 = undefined; 1908 var buttons: [2]ConfirmationButton = undefined; 1909 buttons[0] = .{ .label = switch (confirmation_kind) { 1910 .remove => try std.fmt.bufPrint(&label_buf, "remove {s}", .{event_name}), 1911 .publish => "publish patch", 1912 .merge => "merge patch", 1913 } }; 1914 var button_count: usize = 1; 1915 if (confirmation_kind == .merge) { 1916 if (comptime supports_merge) { 1917 const availability = if (data.selectedThread()) |entry| 1918 if (Data.canMerge(entry.*, session)) entry.mergeability else pch.Mergeability{} 1919 else 1920 pch.Mergeability{}; 1921 buttons[0].bottom_label = mergeBottomLabel(availability.source); 1922 if (availability.source != .clean) buttons[0].action = ""; 1923 buttons[1] = .{ 1924 .label = "squash and merge patch", 1925 .bottom_label = mergeBottomLabel(availability.squash), 1926 .action = if (availability.squash == .clean) try aa.print("{s}{s}/squash", .{ ui.submit_action_prefix, page_url }) else "", 1927 }; 1928 button_count += 1; 1929 } else unreachable; 1930 } 1931 var center = try initConfirmationForm(allocator, action, buttons[0..button_count]); 1932 errdefer center.deinit(allocator); 1933 try stack.children.put(allocator, center.getFocus().id, .{ .center = center }); 1934 } else if (data.view == .new_comment or data.view == .edit_comment) { 1935 const editing = data.view == .edit_comment; 1936 const route = if (editing) 1937 ui.RoutablePage.repoThreadCommentEditRoute(kind, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong 1938 else 1939 ui.RoutablePage.repoThreadCommentNewRoute(kind, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong; 1940 const page_url = try route.toUrl(session.page_arena); 1941 const action = try session.page_arena.allocator().print("form:{s}", .{page_url}); 1942 const page = data.comment_page; 1943 const top_level = if (page) |p| std.mem.eql(u8, &p.selected.comment.event.parent_id, &p.selected.comment.event.thread_id) else false; 1944 const parent_route = if (editing) 1945 if (top_level) 1946 ui.RoutablePage.repoThreadCommentsRoute(kind, data.identity, data.selected_id, 0) 1947 else if (page) |p| 1948 ui.RoutablePage.repoThreadCommentRoute(kind, data.identity, data.selected_id, &p.selected.comment.event.parent_id, 0) 1949 else 1950 null 1951 else if (page) |p| 1952 ui.RoutablePage.repoThreadCommentRoute(kind, data.identity, data.selected_id, &p.selected.id, 0) 1953 else 1954 ui.RoutablePage.repoThreadCommentsRoute(kind, data.identity, data.selected_id, 0); 1955 const parent_author: ui.Author = if (editing) 1956 if (top_level) 1957 if (data.selectedThread()) |entry| entry.author else .unknown 1958 else if (page) |p| 1959 p.selected.parent_author orelse .unknown 1960 else 1961 .unknown 1962 else if (page) |p| 1963 p.selected.author 1964 else if (data.selectedThread()) |entry| 1965 entry.author 1966 else 1967 .unknown; 1968 const initial_body: ?[]const u8 = if (editing) if (page) |p| p.selected.comment.event.body else null else null; 1969 var form = try initCommentForm(allocator, session, action, parent_author, parent_route orelse return error.RouteTooLong, initial_body); 1970 errdefer form.deinit(allocator); 1971 try stack.children.put(allocator, form.getFocus().id, .{ .box = form }); 1972 } else if (supports_conflicts and data.view == .resolve) { 1973 // on the web the page grows to the form's height and the 1974 // browser scrolls it; the terminal scrolls the form itself 1975 var form_widget: Widget = blk: { 1976 var form = try initResolveForm(allocator, session, data); 1977 errdefer form.deinit(allocator); 1978 break :blk if (session.is_terminal) 1979 .{ .scroll = try wgt.Scroll(Widget).init(allocator, .{ .box = form }, .{ .direction = .vert }) } 1980 else 1981 .{ .box = form }; 1982 }; 1983 errdefer form_widget.deinit(allocator); 1984 try stack.children.put(allocator, form_widget.getFocus().id, form_widget); 1985 } else { 1986 const aa = session.page_arena.allocator(); 1987 const route = if (data.view == .edit) 1988 ui.RoutablePage.repoThreadEditRoute(kind, data.identity, data.selected_id) orelse return error.RouteTooLong 1989 else 1990 ui.RoutablePage.repoThreadNewRoute(kind, data.identity) orelse return error.RouteTooLong; 1991 const action = try aa.print("form:{s}", .{try route.toUrl(session.page_arena)}); 1992 const record = if (data.view == .edit) 1993 (if (data.selectedThread()) |entry| &entry.record else null) 1994 else 1995 null; 1996 var form = try initThreadForm(allocator, session, data, action, record); 1997 errdefer form.deinit(allocator); 1998 try stack.children.put(allocator, form.getFocus().id, .{ .box = form }); 1999 } 2000 } else { 2001 var message = try ui.Unauthorized.View.init(allocator); 2002 errdefer message.deinit(allocator); 2003 try stack.children.put(allocator, message.getFocus().id, .{ .unauthorized = message }); 2004 } 2005 2006 if (supports_drafts) { 2007 var split = try initSplit(allocator, session, data, null, true); 2008 errdefer split.deinit(allocator); 2009 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 2010 } 2011 2012 // the conflicts split; its tab exists only when the repo has 2013 // conflicts, so skip the child too to keep the stack 1:1 with the 2014 // tabs. 2015 if (supports_conflicts and data.conflicts.count > 0) { 2016 var split = try initSplit(allocator, session, data, null, false); 2017 errdefer split.deinit(allocator); 2018 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 2019 } 2020 2021 // the stack starts on the page's view. 2022 stack.getFocus().child_id = stack.children.keys()[viewIndex(data.view)]; 2023 2024 // focus entering the view lands on the tabs first. 2025 outer.getFocus().child_id = outer.children.keys()[header_index]; 2026 2027 return .{ 2028 .box = outer, 2029 .data = data, 2030 .session = session, 2031 }; 2032 } 2033 2034 // the master-detail split showing `status`'s window, or the conflicts 2035 // window when null. 2036 fn initSplit(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self, status_maybe: ?Status, drafts: bool) !wgt.Box(Widget) { 2037 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .horiz }); 2038 errdefer box.deinit(allocator); 2039 2040 const win = if (status_maybe) |status| data.window(status) else if (drafts and supports_drafts) &data.drafts else if (supports_conflicts) &data.conflicts else unreachable; 2041 2042 // the thread list (one focusable row per title), plus a "next" link that 2043 // reloads the page rooted at the following thread. 2044 { 2045 var list_scroll = blk: { 2046 var list_box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert, .stretch = true }); 2047 errdefer list_box.deinit(allocator); 2048 if (win.prev_id) |prev| 2049 try addRow(allocator, &list_box, "← previous", "", try windowLink(session.page_arena, data, status_maybe, drafts, prev)); 2050 for (win.items) |entry| { 2051 const label: []const u8 = if (entry.comments.count > 0) 2052 try session.page_arena.allocator().print(" {d} comments ", .{entry.comments.count}) 2053 else 2054 ""; 2055 try addRow(allocator, &list_box, entry.record.event.title, label, try rowLink(session.page_arena, data, entry.id)); 2056 } 2057 if (win.next_id) |next| 2058 try addRow(allocator, &list_box, "next →", "", try windowLink(session.page_arena, data, status_maybe, drafts, next)); 2059 // select the window's first thread (past a leading "previous" 2060 // row) so its description shows on load. 2061 if (win.items.len > 0) 2062 list_box.getFocus().child_id = list_box.children.keys()[if (win.prev_id != null) 1 else 0] 2063 else if (list_box.children.count() > 0) 2064 list_box.getFocus().child_id = list_box.children.keys()[0]; 2065 break :blk try wgt.Scroll(Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal }); 2066 }; 2067 errdefer list_scroll.deinit(allocator); 2068 try box.children.put(allocator, list_scroll.getFocus().id, .{ .widget = .{ .scroll = list_scroll }, .rect = null, .min_size = .{ .width = list_max_width, .height = null }, .max_size = .{ .width = list_max_width, .height = null } }); 2069 } 2070 2071 // frame the detail pane inside the master-detail split, below the 2072 // way back to the list, shown only while the list is hidden 2073 { 2074 var frame = try wgt.Box(Widget).init(allocator, .{ .border = .hidden, .direction = .vert }); 2075 errdefer frame.deinit(allocator); 2076 frame.getFocus().mode = .mouse; 2077 try widget.addListBack(allocator, &frame, "← back to " ++ thread_name ++ " list"); 2078 var detail_view = try DetailType.init(allocator, data, session, null, .{}); 2079 errdefer detail_view.deinit(allocator); 2080 frame.getFocus().child_id = detail_view.getFocus().id; 2081 try frame.children.put(allocator, detail_view.getFocus().id, .{ .widget = @unionInit(Widget, Data.detail_widget_name, detail_view), .rect = null, .min_size = null }); 2082 try box.children.put(allocator, frame.getFocus().id, .{ .widget = .{ .box = frame }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 2083 } 2084 2085 // the page opens on the list, unless the url names a thread 2086 box.getFocus().child_id = box.children.keys()[if (data.selected_id.len > 0) detail_index else list_index]; 2087 return box; 2088 } 2089 2090 // a thread form, plus the target branch for patches, prefilled from 2091 // `record` when given. its form: subtree makes the web renderer POST 2092 // the inputs to `action`'s route. 2093 fn initThreadForm(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self, action: []const u8, record: ?*const Event.Record) !wgt.Box(Widget) { 2094 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 2095 errdefer box.deinit(allocator); 2096 box.getFocus().kind = .{ .custom = action }; 2097 2098 const saved_form = session.formFeedback(feedback_tag); 2099 const saved_fields = if (saved_form) |saved| saved.fields else null; 2100 2101 { 2102 var title = try wgt.TextInput.init(allocator, .{ .top_label = .{ .text = " title " }, .name = "title", .visible_width = null, .round_corners = true, .render_content = session.is_terminal }); 2103 errdefer title.deinit(allocator); 2104 title.getFocus().mode = .all; 2105 if (saved_fields) |saved| 2106 try title.setContent(allocator, saved.title) 2107 else if (record) |r| 2108 try title.setContent(allocator, r.event.title); 2109 try box.children.put(allocator, title.getFocus().id, .{ .widget = .{ .text_input = title }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 2110 box.getFocus().child_id = title.getFocus().id; 2111 } 2112 2113 { 2114 var labels = try wgt.TextInput.init(allocator, .{ .top_label = .{ .text = " labels (separate with spaces) " }, .name = "labels", .visible_width = null, .round_corners = true, .render_content = session.is_terminal }); 2115 errdefer labels.deinit(allocator); 2116 labels.getFocus().mode = .all; 2117 if (saved_fields) |saved| 2118 try labels.setContent(allocator, saved.labels) 2119 else if (record) |r| 2120 try labels.setContent(allocator, r.event.labels); 2121 try box.children.put(allocator, labels.getFocus().id, .{ .widget = .{ .text_input = labels }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 2122 } 2123 2124 { 2125 var description = try wgt.TextInput.init(allocator, .{ .top_label = .{ .text = " description (markdown supported) " }, .name = "description", .visible_width = null, .round_corners = true, .render_content = session.is_terminal, .multiline = true, .scroll = .{ .fill = true } }); 2126 errdefer description.deinit(allocator); 2127 description.getFocus().mode = .all; 2128 if (saved_fields) |saved| 2129 try description.setContent(allocator, saved.description) 2130 else if (record) |r| 2131 try description.setContent(allocator, r.event.description); 2132 try box.children.put(allocator, description.getFocus().id, .{ .widget = .{ .text_input = description }, .rect = null, .min_size = null }); 2133 } 2134 2135 if (supports_drafts and record == null) { 2136 var source = try Data.Source.init(allocator, session, if (saved_fields) |saved| saved.source_branch else "", if (saved_fields) |saved| saved.source_kind else .fork); 2137 errdefer source.deinit(allocator); 2138 try box.children.put(allocator, source.getFocus().id, .{ .widget = .{ .patch_source = source }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 2139 } 2140 2141 if (supports_drafts) { 2142 var target = try wgt.TextInput.init(allocator, .{ .top_label = .{ .text = " target branch " }, .name = "target_branch", .visible_width = null, .round_corners = true, .render_content = session.is_terminal }); 2143 errdefer target.deinit(allocator); 2144 target.getFocus().mode = .all; 2145 const content = if (saved_fields) |saved| saved.target_branch else if (record) |r| r.event.target_branch else data.default_target_branch; 2146 try target.setContent(allocator, content); 2147 try box.children.put(allocator, target.getFocus().id, .{ .widget = .{ .text_input = target }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 2148 } 2149 2150 try addSubmitButtonLabeled(allocator, &box, if (supports_drafts and record == null) "submit draft" else "submit"); 2151 2152 return box; 2153 } 2154 2155 fn initCommentForm(allocator: std.mem.Allocator, session: *ui.Session, action: []const u8, author: ui.Author, parent_route: ui.RoutablePage, initial_body: ?[]const u8) !wgt.Box(Widget) { 2156 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 2157 errdefer box.deinit(allocator); 2158 box.getFocus().kind = .{ .custom = action }; 2159 2160 { 2161 var parent = try ui.authorBox(allocator, session.page_arena, author); 2162 errdefer parent.deinit(allocator); 2163 parent.options.top_label.text = " replying to "; 2164 parent.getFocus().kind = .{ .custom = try session.page_arena.allocator().print("a:{s}", .{try parent_route.toUrl(session.page_arena)}) }; 2165 try box.children.put(allocator, parent.getFocus().id, .{ .widget = .{ .text_box = parent }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 2166 box.getFocus().child_id = parent.getFocus().id; 2167 } 2168 2169 { 2170 var body = try wgt.TextInput.init(allocator, .{ 2171 .top_label = .{ .text = " comment (markdown supported) " }, 2172 .name = "body", 2173 .visible_width = null, 2174 .round_corners = true, 2175 .render_content = session.is_terminal, 2176 .multiline = true, 2177 .visible_height = 5, 2178 .scroll = .{ .fill = true }, 2179 }); 2180 errdefer body.deinit(allocator); 2181 body.getFocus().mode = .all; 2182 if (initial_body) |text| try body.setContent(allocator, text); 2183 try box.children.put(allocator, body.getFocus().id, .{ .widget = .{ .text_input = body }, .rect = null, .min_size = null }); 2184 } 2185 2186 try addSubmitButtonLabeled(allocator, &box, "submit"); 2187 return box; 2188 } 2189 2190 const ConfirmationButton = struct { 2191 label: []const u8, 2192 bottom_label: []const u8 = "", 2193 action: []const u8 = "submit", 2194 }; 2195 2196 fn initConfirmationForm(allocator: std.mem.Allocator, action: []const u8, buttons: []const ConfirmationButton) !Center { 2197 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .round_corners = true, .direction = .vert }); 2198 errdefer box.deinit(allocator); 2199 box.getFocus().kind = .{ .custom = action }; 2200 2201 var prompt = try wgt.Text.init(allocator, "are you sure?"); 2202 errdefer prompt.deinit(allocator); 2203 try box.children.put(allocator, prompt.getFocus().id, .{ .widget = .{ .text = prompt }, .rect = null, .min_size = null }); 2204 2205 for (buttons, 0..) |options, index| { 2206 var button = try wgt.TextBox.init(allocator, options.label, .{ .border = .single, .round_corners = true, .wrap_kind = .none, .bottom_label = .{ .text = options.bottom_label } }); 2207 errdefer button.deinit(allocator); 2208 button.getFocus().mode = .all; 2209 button.getFocus().kind = .{ .custom = options.action }; 2210 try box.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = null }); 2211 if (index == 0) box.getFocus().child_id = button.getFocus().id; 2212 } 2213 2214 return Center.init(allocator, .{ .box = box }); 2215 } 2216 2217 // a form's submit button, then a spacer absorbing the leftover 2218 // min-height the box hands its last child, so the button keeps its 2219 // natural height 2220 fn addSubmitButtonLabeled(allocator: std.mem.Allocator, box: *wgt.Box(Widget), label: []const u8) !void { 2221 { 2222 var submit = try SubmitButton.initLabeled(allocator, label); 2223 errdefer submit.deinit(allocator); 2224 try box.children.put(allocator, submit.getFocus().id, .{ .widget = .{ .submit_button = submit }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 2225 } 2226 { 2227 var spacer = try Spacer.init(allocator); 2228 errdefer spacer.deinit(allocator); 2229 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 2230 } 2231 } 2232 2233 // the conflict resolve form. the "use this" links are navigations that 2234 // flip the url's theirs: pick, reloading the prefills; one submit 2235 // settles every conflict. the form: subtree makes the web renderer POST 2236 // to the resolve route. 2237 fn initResolveForm(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !wgt.Box(Widget) { 2238 const aa = session.page_arena.allocator(); 2239 // init only picks the resolve view once it has read the conflict 2240 const conflict = if (data.conflict) |*c| c else unreachable; 2241 2242 var box = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .vert }); 2243 errdefer box.deinit(allocator); 2244 const route = resolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong; 2245 box.getFocus().kind = .{ .custom = try aa.print("form:{s}", .{try route.toUrl(session.page_arena)}) }; 2246 2247 if (conflict.title) |*fc| { 2248 try addLabel(allocator, &box, "title conflict:"); 2249 try addFieldConflict(allocator, &box, session, data, "title", fc); 2250 } 2251 if (conflict.labels) |*fc| { 2252 try addLabel(allocator, &box, "labels conflict:"); 2253 try addFieldConflict(allocator, &box, session, data, "labels", fc); 2254 } 2255 if (comptime @hasField(Data.Conflict, "status")) { 2256 if (conflict.status) |*fc| { 2257 try addLabel(allocator, &box, "status conflict:"); 2258 try addAtomicConflict(allocator, &box, session, data, "status", fc); 2259 } 2260 } 2261 if (comptime @hasField(Data.Conflict, "revision")) { 2262 if (conflict.revision) |*fc| { 2263 try addLabel(allocator, &box, "revision conflict:"); 2264 try addAtomicConflict(allocator, &box, session, data, "revision", fc); 2265 } 2266 if (conflict.target_branch) |*fc| { 2267 try addLabel(allocator, &box, "target branch conflict:"); 2268 try addAtomicConflict(allocator, &box, session, data, "target_branch", fc); 2269 } 2270 } 2271 2272 if (conflict.description) |*desc| { 2273 try addLabel(allocator, &box, "description conflict:"); 2274 var hunk_index: usize = 0; 2275 for (desc.chunks, 0..) |*chunk, chunk_index| { 2276 switch (chunk.*) { 2277 .same => |text| { 2278 var tb = try wgt.TextBox.init(allocator, text, .{ .border = .single, .round_corners = true, .wrap_kind = .word }); 2279 errdefer tb.deinit(allocator); 2280 tb.getFocus().mode = .all; 2281 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 2282 }, 2283 // an auto-resolved chunk: only one side changed it, so its 2284 // version stands, shown distinctly with its author 2285 .auto => |auto| { 2286 const author = if (auto.theirs) desc.theirs_author else desc.ours_author; 2287 const verb: []const u8 = if (auto.text == null) "removed" else "edited"; 2288 const label = switch (author) { 2289 .user_name, .email => |name| try aa.print(" {s} by {s} ", .{ verb, name }), 2290 .unknown => try aa.print(" {s} by {s} ", .{ verb, if (auto.theirs) @as([]const u8, "them") else "us" }), 2291 }; 2292 var tb = try wgt.TextBox.init(allocator, auto.text orelse "(removed)", .{ .border = .single, .round_corners = true, .wrap_kind = .word, .top_label = .{ .text = label } }); 2293 errdefer tb.deinit(allocator); 2294 tb.getFocus().mode = .all; 2295 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 2296 }, 2297 .conflict => |hunk| { 2298 // a blank row on each side sets the group apart from 2299 // the flowing shared and auto-resolved chunks 2300 if (chunk_index > 0) try addGap(allocator, &box); 2301 const name = try aa.print("d{d}", .{hunk_index}); 2302 hunk_index += 1; 2303 const picked_theirs = data.theirsPicked(name); 2304 try addVersionRow(allocator, &box, try sideLabel(aa, desc.ours_author, true), hunk.ours orelse "", try useThisLink(session, data, name, false)); 2305 try addVersionRow(allocator, &box, try sideLabel(aa, desc.theirs_author, false), hunk.theirs orelse "", try useThisLink(session, data, name, true)); 2306 var resolution_input = try wgt.TextInput.init(allocator, .{ .top_label = .{ .text = " resolution " }, .name = name, .visible_width = null, .round_corners = true, .render_content = session.is_terminal, .multiline = true }); 2307 errdefer resolution_input.deinit(allocator); 2308 resolution_input.getFocus().mode = .all; 2309 try resolution_input.setContent(allocator, (if (picked_theirs) hunk.theirs else hunk.ours) orelse ""); 2310 try box.children.put(allocator, resolution_input.getFocus().id, .{ .widget = .{ .text_input = resolution_input }, .rect = null, .min_size = null }); 2311 if (chunk_index + 1 < desc.chunks.len) try addGap(allocator, &box); 2312 }, 2313 } 2314 } 2315 } 2316 2317 try addSubmitButtonLabeled(allocator, &box, "submit"); 2318 2319 box.getFocus().child_id = box.children.keys()[0]; 2320 return box; 2321 } 2322 2323 // one conflicted scalar field: both sides' version rows, then the 2324 // resolution input prefilled from the picked side. 2325 fn addFieldConflict(allocator: std.mem.Allocator, box: *wgt.Box(Widget), session: *ui.Session, data: *const Self, comptime name: []const u8, fc: *const FieldConflict) !void { 2326 const aa = session.page_arena.allocator(); 2327 try addVersionRow(allocator, box, try sideLabel(aa, fc.ours.author, true), fc.ours.text, try useThisLink(session, data, name, false)); 2328 try addVersionRow(allocator, box, try sideLabel(aa, fc.theirs.author, false), fc.theirs.text, try useThisLink(session, data, name, true)); 2329 2330 var resolution_input = try wgt.TextInput.init(allocator, .{ .top_label = .{ .text = " resolution " }, .name = name, .visible_width = null, .round_corners = true, .render_content = session.is_terminal }); 2331 errdefer resolution_input.deinit(allocator); 2332 resolution_input.getFocus().mode = .all; 2333 try resolution_input.setContent(allocator, if (data.theirsPicked(name)) fc.theirs.text else fc.ours.text); 2334 try box.children.put(allocator, resolution_input.getFocus().id, .{ .widget = .{ .text_input = resolution_input }, .rect = null, .min_size = null }); 2335 } 2336 2337 // atomic fields can only pick one complete side 2338 fn addAtomicConflict(allocator: std.mem.Allocator, box: *wgt.Box(Widget), session: *ui.Session, data: *const Self, comptime name: []const u8, fc: *const FieldConflict) !void { 2339 const aa = session.page_arena.allocator(); 2340 try addVersionRow(allocator, box, try sideLabel(aa, fc.ours.author, true), fc.ours.text, try useThisLink(session, data, name, false)); 2341 try addVersionRow(allocator, box, try sideLabel(aa, fc.theirs.author, false), fc.theirs.text, try useThisLink(session, data, name, true)); 2342 var selected = try wgt.TextBox.init(allocator, if (data.theirsPicked(name)) fc.theirs.text else fc.ours.text, .{ 2343 .border = .single, 2344 .round_corners = true, 2345 .wrap_kind = .word, 2346 .top_label = .{ .text = " resolution " }, 2347 }); 2348 errdefer selected.deinit(allocator); 2349 selected.getFocus().mode = .all; 2350 try box.children.put(allocator, selected.getFocus().id, .{ .widget = .{ .text_box = selected }, .rect = null, .min_size = null }); 2351 } 2352 2353 // a blank row setting a conflict group apart from its neighbors 2354 fn addGap(allocator: std.mem.Allocator, box: *wgt.Box(Widget)) !void { 2355 var text = try wgt.Text.init(allocator, " "); 2356 errdefer text.deinit(allocator); 2357 try box.children.put(allocator, text.getFocus().id, .{ .widget = .{ .text = text }, .rect = null, .min_size = null }); 2358 } 2359 2360 fn addLabel(allocator: std.mem.Allocator, box: *wgt.Box(Widget), content: []const u8) !void { 2361 var label = try SectionLabel.init(allocator, content); 2362 errdefer label.deinit(allocator); 2363 try box.children.put(allocator, label.getFocus().id, .{ .widget = .{ .section_label = label }, .rect = null, .min_size = null }); 2364 } 2365 2366 // one side of a conflict: the "use this" link on the left, the version 2367 // itself as a labeled read-only box. 2368 fn addVersionRow(allocator: std.mem.Allocator, box: *wgt.Box(Widget), label: []const u8, text: []const u8, link: []const u8) !void { 2369 var row = try wgt.Box(Widget).init(allocator, .{ .border = null, .direction = .horiz }); 2370 errdefer row.deinit(allocator); 2371 2372 { 2373 const use_label = "use this"; 2374 var use = try wgt.TextBox.init(allocator, use_label, .{ .border = .single, .round_corners = true, .wrap_kind = .none }); 2375 errdefer use.deinit(allocator); 2376 use.getFocus().mode = .all; 2377 use.getFocus().kind = .{ .custom = link }; 2378 try row.children.put(allocator, use.getFocus().id, .{ 2379 .widget = .{ .text_box = use }, 2380 .rect = null, 2381 .min_size = .{ .width = use_label.len + 2, .height = null }, 2382 .max_size = .{ .width = use_label.len + 2, .height = null }, 2383 }); 2384 } 2385 2386 { 2387 var tb = try wgt.TextBox.init(allocator, if (text.len > 0) text else "(removed)", .{ .border = .single, .round_corners = true, .wrap_kind = .word, .top_label = .{ .text = label } }); 2388 errdefer tb.deinit(allocator); 2389 tb.getFocus().mode = .all; 2390 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 2391 } 2392 2393 row.getFocus().child_id = row.children.keys()[0]; 2394 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 2395 } 2396 2397 // the label of one side's version box, naming its author 2398 fn sideLabel(aa: std.mem.Allocator, author: ui.Author, ours: bool) ![]const u8 { 2399 return switch (author) { 2400 .user_name, .email => |name| try aa.print(" edited by {s} ", .{name}), 2401 .unknown => if (ours) " current version " else " their version ", 2402 }; 2403 } 2404 2405 // the a: link that reloads the resolve page with `name` picked from ours 2406 // or theirs, reprefilling its resolution input 2407 fn useThisLink(session: *ui.Session, data: *const Self, name: []const u8, theirs: bool) ![]const u8 { 2408 const aa = session.page_arena.allocator(); 2409 var picks: std.ArrayList(u8) = .empty; 2410 var it = std.mem.splitScalar(u8, data.theirs_picks, ','); 2411 while (it.next()) |pick| { 2412 if (pick.len == 0 or std.mem.eql(u8, pick, name)) continue; 2413 if (picks.items.len > 0) try picks.append(aa, ','); 2414 try picks.appendSlice(aa, pick); 2415 } 2416 if (theirs) { 2417 if (picks.items.len > 0) try picks.append(aa, ','); 2418 try picks.appendSlice(aa, name); 2419 } 2420 const route = resolveRoute(data.identity, data.selected_id, picks.items) orelse return error.RouteTooLong; 2421 return aa.print("a:{s}", .{try route.toUrl(session.page_arena)}); 2422 } 2423 2424 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(Widget), text: []const u8, bottom_label: []const u8, link: []const u8) !void { 2425 var row = try wgt.TextBox.init(allocator, text, .{ .border = .hidden, .round_corners = true, .wrap_kind = .word, .bottom_label = .{ .text = bottom_label } }); 2426 errdefer row.deinit(allocator); 2427 row.getFocus().mode = .all; 2428 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 2429 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 2430 } 2431 2432 pub fn deinit(self: *This, allocator: std.mem.Allocator) void { 2433 self.box.deinit(allocator); 2434 } 2435 2436 fn header(self: *This) *HeaderType { 2437 return &@field(self.box.children.values()[header_index].widget, Data.header_widget_name); 2438 } 2439 2440 fn viewStack(self: *This) *wgt.Stack(Widget) { 2441 return &self.box.children.values()[stack_index].widget.stack; 2442 } 2443 2444 // `index`'s master-detail split inside the stack. 2445 fn resultsBox(self: *This, index: usize) *wgt.Box(Widget) { 2446 return &self.viewStack().children.values()[index].box; 2447 } 2448 2449 // the labels view's flow inside the stack. 2450 fn labelsView(self: *This) *WordFlow { 2451 return &self.viewStack().children.values()[labels_view_index].word_flow; 2452 } 2453 2454 // the non-confirmation form inside the stack 2455 fn formBox(self: *This) ?*wgt.Box(Widget) { 2456 return switch (self.viewStack().children.values()[form_view_index]) { 2457 .box => |*box| box, 2458 // the resolve form sits inside a scroll on the terminal 2459 .scroll => |*scroll| &scroll.child.box, 2460 else => null, 2461 }; 2462 } 2463 2464 fn threadForm(self: *This) ?*wgt.Box(Widget) { 2465 if (supports_conflicts and self.data.view == .resolve) return null; 2466 return switch (self.data.view) { 2467 .new_comment, .edit_comment => null, 2468 else => self.formBox(), 2469 }; 2470 } 2471 2472 fn formField(form: *wgt.Box(Widget), name: []const u8) !*wgt.TextInput { 2473 for (form.children.values()) |*child| switch (child.widget) { 2474 .text_input => |*text_input| if (std.mem.eql(u8, text_input.options.name, name)) return text_input, 2475 else => {}, 2476 }; 2477 return error.MissingFormField; 2478 } 2479 2480 fn formWidget(form: *wgt.Box(Widget), comptime widget_kind: std.meta.Tag(Widget)) ?*@FieldType(Widget, @tagName(widget_kind)) { 2481 for (form.children.values()) |*child| { 2482 if (child.widget == widget_kind) return &@field(child.widget, @tagName(widget_kind)); 2483 } 2484 return null; 2485 } 2486 2487 fn confirmationForm(self: *This) ?*wgt.Box(Widget) { 2488 return switch (self.viewStack().children.values()[form_view_index]) { 2489 .center => |*center| switch (center.child.*) { 2490 .box => |*box| box, 2491 else => null, 2492 }, 2493 else => null, 2494 }; 2495 } 2496 2497 // the resolve form's scroll on the terminal (the web page scrolls itself) 2498 fn resolveScroll(self: *This) ?*wgt.Scroll(Widget) { 2499 return switch (self.viewStack().children.values()[form_view_index]) { 2500 .scroll => |*scroll| scroll, 2501 else => null, 2502 }; 2503 } 2504 2505 fn listScroll(self: *This, index: usize) *wgt.Scroll(Widget) { 2506 return &self.resultsBox(index).children.values()[list_index].widget.scroll; 2507 } 2508 2509 fn listBox(self: *This, index: usize) *wgt.Box(Widget) { 2510 return &self.listScroll(index).child.box; 2511 } 2512 2513 fn detailFrame(self: *This, index: usize) *wgt.Box(Widget) { 2514 return &self.resultsBox(index).children.values()[detail_index].widget.box; 2515 } 2516 2517 fn detail(self: *This, index: usize) *DetailType { 2518 return &@field(self.detailFrame(index).children.values()[widget.list_pane_index].widget, Data.detail_widget_name); 2519 } 2520 2521 fn window(self: *This, index: usize) *const Window { 2522 if (supports_conflicts and index == conflict_view_index) return &self.data.conflicts; 2523 if (supports_drafts and index == drafts_view_index) return &self.data.drafts; 2524 return self.data.window(splitStatus(index)); 2525 } 2526 2527 fn stackSelectedIndex(self: *This) ?usize { 2528 const stack = self.viewStack(); 2529 const cid = stack.getFocus().child_id orelse return null; 2530 return stack.children.getIndex(cid); 2531 } 2532 2533 // the stack's selected master-detail split (null when the labels view or the 2534 // new-thread form shows). 2535 fn selectedSplitIndex(self: *This) ?usize { 2536 const idx = self.stackSelectedIndex() orelse return null; 2537 return if (idx < status_count or (supports_drafts and idx == drafts_view_index) or idx == conflict_view_index) idx else null; 2538 } 2539 2540 fn detailActive(self: *This, index: usize) bool { 2541 const rb = self.resultsBox(index); 2542 const cid = rb.getFocus().child_id orelse return false; 2543 return rb.children.getIndex(cid) == detail_index; 2544 } 2545 2546 fn headerActive(self: *This) bool { 2547 const cid = self.box.getFocus().child_id orelse return false; 2548 return self.box.children.getIndex(cid) == header_index; 2549 } 2550 2551 fn labelsViewActive(self: *This) bool { 2552 if (self.headerActive()) return false; 2553 return self.stackSelectedIndex() == labels_view_index; 2554 } 2555 2556 fn formViewActive(self: *This) bool { 2557 if (self.headerActive()) return false; 2558 return self.stackSelectedIndex() == form_view_index; 2559 } 2560 2561 // the selected thread's index, or null when a window-navigation row is 2562 // selected (a leading "previous" row shifts the thread rows down by one). 2563 fn selectedThreadIndex(self: *This, index: usize) ?usize { 2564 const lb = self.listBox(index); 2565 const cid = lb.getFocus().child_id orelse return null; 2566 const idx = lb.children.getIndex(cid) orelse return null; 2567 const win = self.window(index); 2568 const lead: usize = if (win.prev_id != null) 1 else 0; 2569 if (idx < lead or idx - lead >= win.items.len) return null; 2570 return idx - lead; 2571 } 2572 2573 // swap the detail pane to the selected thread when it changes 2574 fn refreshDetail(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2575 const selected = self.selectedThreadIndex(index) orelse return; 2576 const entry = self.window(index).items[selected]; 2577 const changed = if (self.detail(index).entry) |current| !std.mem.eql(u8, current.id, entry.id) else true; 2578 if (!changed) return; 2579 try self.detail(index).setEntry(allocator, entry); 2580 widget.setListBackLink(self.detailFrame(index), try rowLink(self.session.page_arena, self.data, entry.id)); 2581 } 2582 2583 pub fn build(self: *This, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2584 self.clearGrid(); 2585 2586 // each header tab maps 1:1 to a stack child by position 2587 if (self.header().getSelectedIndex()) |index| { 2588 const stack = self.viewStack(); 2589 stack.getFocus().child_id = stack.children.keys()[index]; 2590 } 2591 2592 if (self.selectedSplitIndex()) |i| { 2593 // whether the detail pane fits beside the list, which decides 2594 // the list cap below and whether the detail carries a way back 2595 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 2596 try self.refreshDetail(allocator, i); 2597 widget.showListBack(self.detailFrame(i), !both_panes_fit); 2598 2599 // the selected list row shows a border (the focused TextBox 2600 // upgrades it to a double border itself); the rest stay borderless. 2601 const lb = self.listBox(i); 2602 for (lb.children.keys(), lb.children.values()) |id, *child| { 2603 switch (child.widget) { 2604 .text_box => |*tb| widget.markSelected(tb, lb.getFocus().child_id == id), 2605 else => {}, 2606 } 2607 } 2608 2609 // cap the list at list_max_width only while the detail pane fits 2610 // beside it. the box drops the detail when the width can't hold 2611 // both minimums, so when it's that narrow we lift the cap and let 2612 // the list fill the whole width. 2613 self.resultsBox(i).children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 2614 2615 // stretch the detail pane across the rest of the width so it fills 2616 // the area rather than shrinking to its content; its scroll fills 2617 // the pane. 2618 if (constraint.max_size.width) |w| { 2619 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = if (both_panes_fit) w - list_max_width else w, .height = null }; 2620 } else { 2621 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 2622 } 2623 } 2624 2625 // refresh the form inputs' entries in the session's focus-id -> input 2626 // map with this frame's addresses, so the web/wasm form handling can 2627 // find them by focus id 2628 if (self.threadForm()) |form| { 2629 const failure = if (self.session.formFeedback(feedback_tag)) |saved| saved.failure else null; 2630 (try formField(form, "title")).options.top_label.text = if (failure == .required_title) " title (required) " else " title "; 2631 if (comptime supports_drafts) { 2632 if (formWidget(form, .patch_source)) |source| { 2633 source.field().options.top_label.text = if (failure == .invalid_source_branch) " source branch (not found) " else if (failure == .same_branch) " source branch (same as target) " else if (failure == .unrelated_branches) " source branch (unrelated) " else " source branch "; 2634 const submit = formWidget(form, .submit_button) orelse return error.MissingFormField; 2635 try submit.setLabel(allocator, switch (source.selectedKind()) { 2636 .fork => "submit draft", 2637 .branch => "submit patch", 2638 }); 2639 } 2640 (try formField(form, "target_branch")).options.top_label.text = 2641 if (failure == .invalid_target_branch) " target branch (invalid) " else if (self.data.view == .edit and failure == .same_branch) " target branch (same as source) " else if (self.data.view == .edit and failure == .unrelated_branches) " target branch (unrelated to source) " else if (self.data.view == .edit and failure == .invalid_source_branch) " target branch (source branch not found) " else " target branch "; 2642 } 2643 } 2644 if (self.formBox()) |form| { 2645 const inputs_arena = self.session.arena.allocator(); 2646 for (form.children.values()) |*child| switch (child.widget) { 2647 .text_input => |*ti| try self.session.text_inputs.put(inputs_arena, ti.getFocus().id, ti), 2648 else => {}, 2649 }; 2650 } 2651 2652 try self.box.build(allocator, constraint, root_focus); 2653 } 2654 2655 pub fn input(self: *This, allocator: std.mem.Allocator, raw_key: Key, root_focus: *Focus) !void { 2656 // wheel input moves focus like the arrows 2657 const key: Key = switch (raw_key) { 2658 .scroll_up => .arrow_up, 2659 .scroll_down => .arrow_down, 2660 else => raw_key, 2661 }; 2662 2663 if (self.headerActive()) { 2664 // down from the sub-header re-enters the stack if the selected 2665 // view has something to focus; enter in the search box submits 2666 // the query; other keys move within the sub-header. 2667 if (inp.vertDirection(key) == .down) { 2668 const enterable = if (self.viewStack().getSelected()) |selected| switch (selected.*) { 2669 .word_flow => |*tf| tf.text_boxes.items.len > 0, 2670 // nothing focusable in the unauthorized view 2671 .unauthorized => false, 2672 else => true, 2673 } else false; 2674 if (enterable) root_focus.setFocus(self.box.children.keys()[stack_index]); 2675 } else if (key == .enter) { 2676 if (try self.header().submittedText(allocator)) |submission| { 2677 defer allocator.free(submission.text); 2678 switch (submission.kind) { 2679 .search => try self.submitSearch(submission.text), 2680 .assignee => try self.submitAssignee(submission.text), 2681 } 2682 } 2683 } else { 2684 try self.header().input(allocator, key, root_focus); 2685 } 2686 return; 2687 } 2688 if (self.labelsViewActive()) { 2689 self.labelsViewInput(key, root_focus); 2690 return; 2691 } 2692 if (self.formViewActive()) { 2693 if (confirmation(self.data.view) != null) { 2694 try self.confirmationFormInput(allocator, key, root_focus); 2695 } else if (supports_conflicts and self.data.view == .resolve) { 2696 try self.resolveInput(allocator, key, root_focus); 2697 } else { 2698 try self.formInput(allocator, key, root_focus); 2699 } 2700 return; 2701 } 2702 const i = self.selectedSplitIndex() orelse return; 2703 if (self.detailActive(i)) { 2704 // the way back to the list, by enter or a click 2705 if (widget.listBackId(self.detailFrame(i))) |id| { 2706 if (inp.activated(root_focus, id, key)) return self.focusList(i, root_focus); 2707 if (root_focus.grandchild_id == id) return switch (key) { 2708 .arrow_left => self.focusList(i, root_focus), 2709 .arrow_up => self.focusHeader(root_focus), 2710 .arrow_down => _ = self.detail(i).focusFirst(root_focus), 2711 else => {}, 2712 }; 2713 } 2714 switch (try self.detail(i).inputWithExit(allocator, key, root_focus)) { 2715 .none => {}, 2716 .list => self.focusList(i, root_focus), 2717 .header => if (widget.listBackId(self.detailFrame(i))) |id| root_focus.setFocus(id) else self.focusHeader(root_focus), 2718 } 2719 } else { 2720 try self.listInput(allocator, i, key, root_focus); 2721 } 2722 } 2723 2724 // navigate to the typed query's results, keeping the label filter and the 2725 // status list the page shows. an empty box clears a filtered page and 2726 // does nothing on any other one. 2727 fn submitSearch(self: *This, text: []const u8) !void { 2728 if (text.len == 0 and self.data.search == null) return; 2729 const selected = self.header().getSelectedIndex() orelse 0; 2730 const status: Status = if (selected < status_count) splitStatus(selected) else @fromBackingInt(@intCast(0)); 2731 var route = listRoute(self.data.identity, status, self.data.label, "") orelse return; 2732 const assignee = assigneeFilter(self.data); 2733 if (assignee.len != 0) route = route.withEncodedAssignee(assignee) orelse return; 2734 try self.session.navigate(route.withSearch(text) orelse return); 2735 } 2736 2737 // navigate to the issues assigned to the typed name or email, keeping 2738 // the label, the search and the status list. an empty box clears the 2739 // filter and does nothing on an unfiltered page. 2740 fn submitAssignee(self: *This, typed: []const u8) !void { 2741 const text = std.mem.trim(u8, typed, " \t"); 2742 if (text.len == 0 and assigneeFilter(self.data).len == 0) return; 2743 const selected = self.header().getSelectedIndex() orelse 0; 2744 const status: Status = if (selected < status_count) splitStatus(selected) else @fromBackingInt(@intCast(0)); 2745 var route = listRoute(self.data.identity, status, self.data.label, "") orelse return; 2746 if (self.data.search) |search| route = route.withSearch(search) orelse return; 2747 try self.session.navigate(route.withEncodedAssignee(try ui.urlEncodeRef(self.session.page_arena.allocator(), text)) orelse return); 2748 } 2749 2750 // arrow keys move the label selection; up from the top row crosses to the 2751 // header tabs. 2752 fn labelsViewInput(self: *This, key: Key, root_focus: *Focus) void { 2753 const tf = self.labelsView(); 2754 const cid = tf.focus.child_id orelse return; 2755 const cur = tf.indexOfFocusId(cid) orelse return; 2756 const count = tf.text_boxes.items.len; 2757 switch (key) { 2758 .arrow_left => if (cur > 0) root_focus.setFocus(tf.text_boxes.items[cur - 1].getFocus().id), 2759 .arrow_right => if (cur + 1 < count) root_focus.setFocus(tf.text_boxes.items[cur + 1].getFocus().id), 2760 .arrow_up => if (tf.rowStep(cur, false)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id) else self.focusHeader(root_focus), 2761 .arrow_down => if (tf.rowStep(cur, true)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id), 2762 .home => root_focus.setFocus(tf.text_boxes.items[0].getFocus().id), 2763 .end => root_focus.setFocus(tf.text_boxes.items[count - 1].getFocus().id), 2764 else => {}, 2765 } 2766 } 2767 2768 fn listInput(self: *This, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 2769 // up/down (and the scroll wheel) move the selection a row; page up/down 2770 // jump a fixed amount. right/Enter cross into the detail pane. up from 2771 // the top row crosses into the header tabs. 2772 if (inp.rowDelta(key, @intCast(self.listBox(index).children.count()))) |delta| { 2773 const lb = self.listBox(index); 2774 const at_top = if (lb.getFocus().child_id) |cid| lb.children.getIndex(cid) == 0 else true; 2775 if (delta < 0 and at_top) return self.focusHeader(root_focus); 2776 moveRowFocus(lb, self.listScroll(index), root_focus, delta); 2777 return; 2778 } 2779 switch (key) { 2780 .enter, .arrow_right => self.focusDetail(index, root_focus), 2781 // when the window is too narrow to lay out the detail pane beside 2782 // the list, a click on a row opens it like enter. the row was just 2783 // selected, so the detail is swapped to it ahead of the build. 2784 .mouse => |mouse| if (self.resultsBox(index).children.values()[detail_index].rect == null and widget.clickOnSelectedRow(self.listBox(index), root_focus, mouse)) { 2785 try self.refreshDetail(allocator, index); 2786 self.focusDetail(index, root_focus); 2787 }, 2788 else => {}, 2789 } 2790 } 2791 2792 fn formInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2793 const form = self.formBox() orelse return; 2794 const cid = form.getFocus().child_id orelse return; 2795 const cur = form.children.getIndex(cid) orelse return; 2796 const child = &form.children.values()[cur]; 2797 2798 if (child.widget == .text_input) { 2799 const text_input = &child.widget.text_input; 2800 if (text_input.options.multiline and try multilineKeepsKey(text_input, allocator, key)) 2801 return child.widget.input(allocator, key, root_focus); 2802 } 2803 2804 const on_submit = child.widget == .submit_button; 2805 switch (key) { 2806 .arrow_up, .back_tab => return if (formStep(form, cur, false)) |i| 2807 root_focus.setFocus(form.children.keys()[i]) 2808 else 2809 self.focusHeader(root_focus), 2810 .arrow_down, .tab => return if (formStep(form, cur, true)) |i| root_focus.setFocus(form.children.keys()[i]), 2811 .enter => if (on_submit) return self.submitForm(allocator), 2812 .mouse => |mouse| if (on_submit) { 2813 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) return self.submitForm(allocator); 2814 }, 2815 else => {}, 2816 } 2817 try child.widget.input(allocator, key, root_focus); 2818 } 2819 2820 fn confirmationFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2821 const form = self.confirmationForm() orelse return; 2822 const child_id = form.getFocus().child_id orelse return; 2823 const index = form.children.getIndex(child_id) orelse return; 2824 switch (key) { 2825 .arrow_up, .back_tab => if (index > 1) 2826 root_focus.setFocus(form.children.keys()[index - 1]) 2827 else 2828 self.focusHeader(root_focus), 2829 .arrow_down, .tab => if (index + 1 < form.children.count()) root_focus.setFocus(form.children.keys()[index + 1]), 2830 .enter => try self.submitConfirmation(allocator, index), 2831 .mouse => |mouse| for (form.children.keys()[1..], 1..) |button_id, button_index| { 2832 if (inp.leftClickOn(root_focus, button_id, mouse)) { 2833 try self.submitConfirmation(allocator, button_index); 2834 break; 2835 } 2836 }, 2837 else => {}, 2838 } 2839 } 2840 2841 // the multiline hunk inputs keep enter and any up/down that has a row to 2842 // move to; enter on a "use this" link is a navigation the host follows 2843 // before this runs. 2844 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2845 const form = self.formBox() orelse return; 2846 const cid = form.getFocus().child_id orelse return; 2847 const cur = form.children.getIndex(cid) orelse return; 2848 const child = &form.children.values()[cur]; 2849 2850 if (child.widget == .text_input) { 2851 const ti = &child.widget.text_input; 2852 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2853 return child.widget.input(allocator, key, root_focus); 2854 } 2855 2856 const on_submit = child.widget == .submit_button; 2857 2858 switch (key) { 2859 .arrow_up, .back_tab => if (formStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2860 .arrow_down, .tab => if (formStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2861 .arrow_left, .arrow_right => switch (child.widget) { 2862 .box => |*row| _ = widget.moveInRow(row, root_focus, key == .arrow_right), 2863 else => try child.widget.input(allocator, key, root_focus), 2864 }, 2865 .enter => if (on_submit) try self.submitResolution(allocator), 2866 .mouse => |mouse| if (on_submit) { 2867 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2868 }, 2869 else => try child.widget.input(allocator, key, root_focus), 2870 } 2871 } 2872 2873 // a multiline input keeps enter and any up/down that has a row to move to 2874 fn multilineKeepsKey(text_input: *wgt.TextInput, allocator: std.mem.Allocator, key: Key) !bool { 2875 return switch (key) { 2876 .enter => true, 2877 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2878 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2879 else => false, 2880 }; 2881 } 2882 2883 // the neighboring form control, skipping spacers and blank rows 2884 fn formStep(form: *wgt.Box(Widget), cur: usize, down: bool) ?usize { 2885 var i = cur; 2886 while (true) { 2887 if (down) { 2888 i += 1; 2889 if (i >= form.children.count()) return null; 2890 } else { 2891 if (i == 0) return null; 2892 i -= 1; 2893 } 2894 const child = &form.children.values()[i]; 2895 if (child.hidden) continue; 2896 switch (child.widget) { 2897 .spacer, .text => continue, 2898 else => return i, 2899 } 2900 } 2901 } 2902 2903 // focus the resolve-form child at `i` (a version row focuses its selected 2904 // child) and keep it visible on the terminal 2905 fn focusResolveChild(self: *This, form: *wgt.Box(Widget), i: usize, root_focus: *Focus) void { 2906 const child = &form.children.values()[i]; 2907 switch (child.widget) { 2908 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2909 else => root_focus.setFocus(form.children.keys()[i]), 2910 } 2911 if (self.session.is_terminal) { 2912 if (self.resolveScroll()) |sc| { 2913 if (child.rect) |rect| sc.scrollToRect(rect); 2914 } 2915 } 2916 } 2917 2918 // re-emit the conflicted thread's event with the resolved content; any 2919 // event on the thread settles its conflict entry. this is the terminal 2920 // path; the web posts the form to the resolve route. 2921 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2922 if (comptime wasm) return; 2923 const io = self.session.io orelse return; 2924 const src = self.data.repo_source orelse return; 2925 const entry = self.data.selectedThread() orelse return; 2926 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 2927 const form = self.formBox() orelse return; 2928 2929 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2930 var title: ?[]u8 = null; 2931 var labels: ?[]u8 = null; 2932 var hunks: std.ArrayList([]const u8) = .empty; 2933 defer { 2934 if (title) |t| allocator.free(t); 2935 if (labels) |t| allocator.free(t); 2936 for (hunks.items) |h| allocator.free(h); 2937 hunks.deinit(allocator); 2938 } 2939 for (form.children.values()) |*child| switch (child.widget) { 2940 .text_input => |*ti| { 2941 const text = try ti.text(allocator); 2942 errdefer allocator.free(text); 2943 if (std.mem.eql(u8, ti.options.name, "title")) { 2944 title = text; 2945 } else if (std.mem.eql(u8, ti.options.name, "labels")) { 2946 labels = text; 2947 } else { 2948 try hunks.append(allocator, text); 2949 } 2950 }, 2951 else => {}, 2952 }; 2953 2954 const id_bytes = try evt.parseEventId(entry.id); 2955 2956 switch (src.repo_kind) { 2957 inline else => |repo_kind| { 2958 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2959 defer any_repo.deinit(io, allocator); 2960 switch (any_repo) { 2961 inline else => |*repo| { 2962 var resolution: Event.Resolve = .{ 2963 .title = title, 2964 .labels = labels, 2965 .hunks = hunks.items, 2966 }; 2967 if (comptime @hasField(Event.Resolve, "theirs")) resolution.theirs = self.data.theirs_picks; 2968 const change = Event.Update{ .resolve = resolution }; 2969 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 2970 // leave the form up for correction 2971 error.InvalidFields => return, 2972 else => |e| return e, 2973 }; 2974 }, 2975 } 2976 }, 2977 } 2978 2979 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2980 try self.session.navigate(route); 2981 } 2982 2983 // commit a new or edited comment and navigate to its permalink. this is the 2984 // terminal path; the web posts the form to its comment route. 2985 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 2986 if (comptime wasm) return; 2987 const io = self.session.io orelse return; 2988 const src = self.data.repo_source orelse return; 2989 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 2990 const author = actor.author; 2991 const form = self.formBox() orelse return; 2992 const body_input = try formField(form, "body"); 2993 const body = try body_input.text(allocator); 2994 defer allocator.free(body); 2995 if (!evt.Comment.fieldsValid(body)) return; 2996 2997 var thread_id: [evt.event_id_size * 2]u8 = undefined; 2998 @memcpy(&thread_id, self.data.selected_id); 2999 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 3000 var parent: [evt.event_id_size * 2]u8 = undefined; 3001 @memcpy(&parent, self.data.comment_id); 3002 break :blk parent; 3003 }; 3004 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 3005 const editing = self.data.view == .edit_comment; 3006 if (editing) { 3007 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3008 if (!try src.canModify(io, allocator, actor, .comment, &comment_id)) return; 3009 } 3010 switch (src.repo_kind) { 3011 inline else => |repo_kind| { 3012 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3013 defer any_repo.deinit(io, allocator); 3014 switch (any_repo) { 3015 inline else => |*repo| if (editing) { 3016 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3017 try evt.Comment.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &comment_id, body, author); 3018 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 3019 } else { 3020 event_id_hex = try evt.Comment.create(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &parent_id, body, author); 3021 }, 3022 } 3023 }, 3024 } 3025 3026 body_input.clear(allocator); 3027 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 3028 try self.session.navigate(route); 3029 } 3030 3031 // terminal form submissions; the web posts to the forms' routes instead 3032 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 3033 switch (self.data.view) { 3034 .new_comment, .edit_comment => try self.submitComment(allocator), 3035 .edit => try self.submitEditedThread(allocator), 3036 else => try self.submitNewThread(allocator), 3037 } 3038 } 3039 3040 // commit the new thread to the repo's events branch and navigate to it. 3041 // this is the terminal path; the web posts the form to the thread route, 3042 // so the wasm side never runs (or compiles) the repo access below. 3043 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 3044 if (comptime wasm) return; 3045 const io = self.session.io orelse return; 3046 const src = self.data.repo_source orelse return; 3047 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3048 3049 const form = self.threadForm() orelse return; 3050 const title_input = try formField(form, "title"); 3051 const labels_input = try formField(form, "labels"); 3052 const description_input = try formField(form, "description"); 3053 3054 const title = try title_input.text(allocator); 3055 defer allocator.free(title); 3056 const labels = try labels_input.text(allocator); 3057 defer allocator.free(labels); 3058 const description = try description_input.text(allocator); 3059 defer allocator.free(description); 3060 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3061 defer if (comptime supports_drafts) allocator.free(target_branch); 3062 3063 if (!Event.fieldsValid(title, labels)) { 3064 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3065 return; 3066 } 3067 3068 if (comptime supports_drafts) { 3069 const source = formWidget(form, .patch_source) orelse return error.MissingFormField; 3070 const source_branch = switch (source.selectedKind()) { 3071 .fork => null, 3072 .branch => try source.field().text(allocator), 3073 }; 3074 defer if (source_branch) |branch| allocator.free(branch); 3075 const event_id_hex = Data.create(self.data, self.session, allocator, actor, title, labels, description, target_branch, source_branch) catch |err| { 3076 const failure = FeedbackFailure.fromError(err) orelse return err; 3077 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3078 return; 3079 }; 3080 title_input.clear(allocator); 3081 labels_input.clear(allocator); 3082 description_input.clear(allocator); 3083 (try formField(form, "target_branch")).clear(allocator); 3084 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 3085 try self.session.navigate(route); 3086 return; 3087 } 3088 3089 var id_bytes: [evt.event_id_size]u8 = undefined; 3090 io.random(&id_bytes); 3091 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 3092 3093 const event = evt.EventWithId{ 3094 .id = event_id_hex, 3095 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 3096 .author = actor.author, 3097 .event = @unionInit(evt.Event, @tagName(kind), Event{ 3098 .title = title, 3099 .description = description, 3100 .labels = labels, 3101 }), 3102 }; 3103 3104 switch (src.repo_kind) { 3105 inline else => |repo_kind| { 3106 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3107 defer any_repo.deinit(io, allocator); 3108 switch (any_repo) { 3109 inline else => |*repo| try evt.consume(self.session.eventHost(), .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 3110 } 3111 }, 3112 } 3113 3114 // wipe the form so a return visit starts fresh 3115 title_input.clear(allocator); 3116 labels_input.clear(allocator); 3117 description_input.clear(allocator); 3118 3119 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), "", &event_id_hex) orelse return; 3120 try self.session.navigate(route); 3121 } 3122 3123 // re-emit the selected thread's event with the form's content (status 3124 // preserved), then reload the thread's page. this is the terminal path; 3125 // the web posts the form to the edit route. 3126 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 3127 if (comptime wasm) return; 3128 const io = self.session.io orelse return; 3129 const entry = self.data.selectedThread() orelse return; 3130 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3131 const author = actor.author; 3132 3133 const form = self.threadForm() orelse return; 3134 const title_input = try formField(form, "title"); 3135 const labels_input = try formField(form, "labels"); 3136 const description_input = try formField(form, "description"); 3137 3138 const title = try title_input.text(allocator); 3139 defer allocator.free(title); 3140 const labels = try labels_input.text(allocator); 3141 defer allocator.free(labels); 3142 const description = try description_input.text(allocator); 3143 defer allocator.free(description); 3144 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3145 defer if (comptime supports_drafts) allocator.free(target_branch); 3146 3147 if (!Event.fieldsValid(title, labels)) { 3148 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3149 return; 3150 } 3151 const src = self.data.repo_source orelse return; 3152 3153 if (comptime supports_drafts) { 3154 if (entryDraft(entry.*)) { 3155 self.data.editDraft(self.session, allocator, author, entry.id, title, labels, description, target_branch) catch |err| { 3156 const failure = FeedbackFailure.fromError(err) orelse return err; 3157 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3158 return; 3159 }; 3160 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 3161 try self.session.navigate(route); 3162 return; 3163 } 3164 } 3165 3166 const id_bytes = try evt.parseEventId(entry.id); 3167 if (!try src.canModify(io, allocator, actor, kind, &id_bytes)) return; 3168 3169 switch (src.repo_kind) { 3170 inline else => |repo_kind| { 3171 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3172 defer any_repo.deinit(io, allocator); 3173 switch (any_repo) { 3174 inline else => |*repo| if (supports_drafts) { 3175 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3176 .title = title, 3177 .labels = labels, 3178 .description = description, 3179 .target_branch = target_branch, 3180 } }, author) catch |err| { 3181 const failure = FeedbackFailure.fromError(err) orelse return err; 3182 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3183 return; 3184 }; 3185 } else if (has_status) 3186 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3187 .title = title, 3188 .labels = labels, 3189 .description = description, 3190 } }, author) 3191 else 3192 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, labels, description, author), 3193 } 3194 }, 3195 } 3196 3197 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 3198 try self.session.navigate(route); 3199 } 3200 3201 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, labels: []const u8, description: []const u8, target_branch: []const u8) !void { 3202 const aa = self.session.arena.allocator(); 3203 const source = if (supports_drafts) blk: { 3204 const form = self.threadForm() orelse break :blk null; 3205 break :blk formWidget(form, .patch_source); 3206 } else null; 3207 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 3208 .failure = failure, 3209 .fields = if (comptime supports_drafts) .{ 3210 .title = try aa.dupe(u8, title), 3211 .labels = try aa.dupe(u8, labels), 3212 .description = try aa.dupe(u8, description), 3213 .target_branch = try aa.dupe(u8, target_branch), 3214 .source_branch = if (source) |value| try value.field().text(aa) else "", 3215 .source_kind = if (source) |value| value.selectedKind() else .fork, 3216 } else .{ 3217 .title = try aa.dupe(u8, title), 3218 .labels = try aa.dupe(u8, labels), 3219 .description = try aa.dupe(u8, description), 3220 }, 3221 }); 3222 } 3223 3224 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3225 switch (confirmation(self.data.view) orelse return) { 3226 .publish => if (comptime supports_drafts) { 3227 if (comptime wasm) return; 3228 const entry = self.data.selectedThread() orelse return; 3229 if (!entryDraft(entry.*)) return; 3230 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3231 try self.data.publishDraft(self.session, allocator, author, entry.id); 3232 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), "", entry.id) orelse return; 3233 try self.session.navigate(route); 3234 } else unreachable, 3235 .merge => if (comptime supports_merge) { 3236 if (comptime wasm) return; 3237 const entry = self.data.selectedThread() orelse return; 3238 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3239 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3240 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3241 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3242 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3243 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 3244 try self.session.navigate(route); 3245 return; 3246 }, 3247 else => return err, 3248 }; 3249 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3250 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 3251 try self.session.navigate(route); 3252 } else unreachable, 3253 .remove => try self.submitRemove(allocator), 3254 } 3255 } 3256 3257 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3258 const comment = self.data.comment_id.len != 0; 3259 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3260 const id = evt.parseEventId(event_id) catch return; 3261 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3262 } 3263 3264 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3265 if (comptime wasm) return; 3266 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3267 const author = actor.author; 3268 3269 if (comptime supports_drafts) { 3270 const selected = self.data.selectedThread() orelse return; 3271 if (event_kind == kind and entryDraft(selected.*)) { 3272 try Data.removeDraft(self.session, allocator, author, &id); 3273 const route = draftsRoute(self.data.identity) orelse return; 3274 try self.session.navigate(route); 3275 return; 3276 } 3277 } 3278 3279 const io = self.session.io orelse return; 3280 const src = self.data.repo_source orelse return; 3281 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3282 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3283 3284 switch (src.repo_kind) { 3285 inline else => |repo_kind| { 3286 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3287 defer any_repo.deinit(io, allocator); 3288 switch (any_repo) { 3289 inline else => |*repo| try evt.removeInThread(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, event_kind, &id, author), 3290 } 3291 }, 3292 } 3293 3294 const id_hex = std.fmt.bytesToHex(id, .lower); 3295 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 3296 try self.session.navigate(route); 3297 } 3298 3299 // enter the detail pane, landing on the way back to the list when it shows 3300 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3301 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3302 _ = self.detail(index).focusFirst(root_focus); 3303 } 3304 3305 // return to the list. 3306 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3307 root_focus.setFocus(self.listScroll(index).getFocus().id); 3308 } 3309 3310 // cross to the header tabs above the stack. 3311 fn focusHeader(self: *This, root_focus: *Focus) void { 3312 root_focus.setFocus(self.box.children.keys()[header_index]); 3313 } 3314 3315 pub fn clearGrid(self: *This) void { 3316 self.box.clearGrid(); 3317 } 3318 3319 pub fn getGrid(self: This) ?Grid { 3320 return self.box.getGrid(); 3321 } 3322 3323 pub fn getFocus(self: *This) *Focus { 3324 return self.box.getFocus(); 3325 } 3326 3327 // for the parent's "scroll up at the top jumps to the header" check: at the 3328 // top only while the header tabs hold focus, so up from the split 3329 // crosses into the tabs first. 3330 pub fn atTop(self: *This) bool { 3331 return self.headerActive(); 3332 } 3333 }; 3334 } 3335