╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1852 try addVersionRow(allocator, box, try sideLabel(aa, fc.ours.author, true), fc.ours.text, try useThisLink(session, data, name, false)); 1853 try addVersionRow(allocator, box, try sideLabel(aa, fc.theirs.author, false), fc.theirs.text, try useThisLink(session, data, name, true)); 1854 var selected = try wgt.TextBox.init(allocator, if (data.theirsPicked(name)) fc.theirs.text else fc.ours.text, .{ 1855 .border_style = .single, 1856 .rounded_corners = true, 1857 .wrap_kind = .word, 1858 .label = " resolution ", 1859 }); 1860 errdefer selected.deinit(allocator); 1861 selected.getFocus().mode = .all; 1862 try box.children.put(allocator, selected.getFocus().id, .{ .widget = .{ .text_box = selected }, .rect = null, .min_size = null }); 1863 } 1864 1865 // a blank row setting a conflict group apart from its neighbors 1866 fn addGap(allocator: std.mem.Allocator, box: *wgt.Box(Widget)) !void { 1867 var text = try wgt.Text.init(allocator, " "); 1868 errdefer text.deinit(allocator); 1869 try box.children.put(allocator, text.getFocus().id, .{ .widget = .{ .text = text }, .rect = null, .min_size = null }); 1870 } 1871 1872 fn addLabel(allocator: std.mem.Allocator, box: *wgt.Box(Widget), content: []const u8) !void { 1873 var label = try SectionLabel.init(allocator, content); 1874 errdefer label.deinit(allocator); 1875 try box.children.put(allocator, label.getFocus().id, .{ .widget = .{ .section_label = label }, .rect = null, .min_size = null }); 1876 } 1877 1878 // one side of a conflict: the "use this" link on the left, the version 1879 // itself as a labeled read-only box. 1880 fn addVersionRow(allocator: std.mem.Allocator, box: *wgt.Box(Widget), label: []const u8, text: []const u8, link: []const u8) !void { 1881 var row = try wgt.Box(Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1882 errdefer row.deinit(allocator); 1883 1884 { 1885 const use_label = "use this"; 1886 var use = try wgt.TextBox.init(allocator, use_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1887 errdefer use.deinit(allocator); 1888 use.getFocus().mode = .all; 1889 use.getFocus().kind = .{ .custom = link }; 1890 try row.children.put(allocator, use.getFocus().id, .{ 1891 .widget = .{ .text_box = use }, 1892 .rect = null, 1893 .min_size = .{ .width = use_label.len + 2, .height = null }, 1894 .max_size = .{ .width = use_label.len + 2, .height = null }, 1895 }); 1896 } 1897 1898 { 1899 var tb = try wgt.TextBox.init(allocator, if (text.len > 0) text else "(removed)", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = label }); 1900 errdefer tb.deinit(allocator); 1901 tb.getFocus().mode = .all; 1902 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1903 } 1904 1905 row.getFocus().child_id = row.children.keys()[0]; 1906 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 1907 } 1908 1909 // the label of one side's version box, naming its author 1910 fn sideLabel(aa: std.mem.Allocator, author: ui.Author, ours: bool) ![]const u8 { 1911 return switch (author) { 1912 .user_name, .email => |name| try std.fmt.allocPrint(aa, " edited by {s} ", .{name}), 1913 .unknown => if (ours) " current version " else " their version ", 1914 }; 1915 } 1916 1917 // the a: link that reloads the resolve page with `name` picked from ours 1918 // or theirs, reprefilling its resolution input 1919 fn useThisLink(session: *ui.Session, data: *const Self, name: []const u8, theirs: bool) ![]const u8 { 1920 const aa = session.page_arena.allocator(); 1921 var picks: std.ArrayList(u8) = .empty; 1922 var it = std.mem.splitScalar(u8, data.theirs_picks, ','); 1923 while (it.next()) |pick| { 1924 if (pick.len == 0 or std.mem.eql(u8, pick, name)) continue; 1925 if (picks.items.len > 0) try picks.append(aa, ','); 1926 try picks.appendSlice(aa, pick); 1927 } 1928 if (theirs) { 1929 if (picks.items.len > 0) try picks.append(aa, ','); 1930 try picks.appendSlice(aa, name); 1931 } 1932 const route = resolveRoute(data.identity, data.selected_id, picks.items) orelse return error.RouteTooLong; 1933 return std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(session.page_arena)}); 1934 } 1935 1936 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(Widget), text: []const u8, bottom_label: []const u8, link: []const u8) !void { 1937 var row = try wgt.TextBox.init(allocator, text, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word, .bottom_label = bottom_label }); 1938 errdefer row.deinit(allocator); 1939 row.getFocus().mode = .all; 1940 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 1941 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 1942 } 1943 1944 pub fn deinit(self: *This, allocator: std.mem.Allocator) void { 1945 self.box.deinit(allocator); 1946 } 1947 1948 fn header(self: *This) *HeaderType { 1949 return &@field(self.box.children.values()[header_index].widget, Data.header_widget_name); 1950 } 1951 1952 fn viewStack(self: *This) *wgt.Stack(Widget) { 1953 return &self.box.children.values()[stack_index].widget.stack; 1954 } 1955 1956 // `index`'s master-detail split inside the stack. 1957 fn resultsBox(self: *This, index: usize) *wgt.Box(Widget) { 1958 return &self.viewStack().children.values()[index].box; 1959 } 1960 1961 // the tags view's flow inside the stack. 1962 fn tagsView(self: *This) *TagFlow { 1963 return &self.viewStack().children.values()[tags_view_index].tag_flow; 1964 } 1965 1966 // the non-confirmation form inside the stack 1967 fn formBox(self: *This) ?*wgt.Box(Widget) { 1968 return switch (self.viewStack().children.values()[form_view_index]) { 1969 .box => |*box| box, 1970 // the resolve form sits inside a scroll on the terminal 1971 .scroll => |*scroll| &scroll.child.box, 1972 else => null, 1973 }; 1974 } 1975 1976 fn threadForm(self: *This) ?*wgt.Box(Widget) { 1977 if (supports_conflicts and self.data.view == .resolve) return null; 1978 return switch (self.data.view) { 1979 .new_comment, .edit_comment => null, 1980 else => self.formBox(), 1981 }; 1982 } 1983 1984 fn formField(form: *wgt.Box(Widget), name: []const u8) !*wgt.TextInput { 1985 for (form.children.values()) |*child| switch (child.widget) { 1986 .text_input => |*text_input| if (std.mem.eql(u8, text_input.options.name, name)) return text_input, 1987 else => {}, 1988 }; 1989 return error.MissingFormField; 1990 } 1991 1992 fn formWidget(form: *wgt.Box(Widget), comptime widget_kind: std.meta.Tag(Widget)) ?*@FieldType(Widget, @tagName(widget_kind)) { 1993 for (form.children.values()) |*child| { 1994 if (child.widget == widget_kind) return &@field(child.widget, @tagName(widget_kind)); 1995 } 1996 return null; 1997 } 1998 1999 fn confirmationForm(self: *This) ?*wgt.Box(Widget) { 2000 return switch (self.viewStack().children.values()[form_view_index]) { 2001 .center => |*center| switch (center.child.*) { 2002 .box => |*box| box, 2003 else => null, 2004 }, 2005 else => null, 2006 }; 2007 } 2008 2009 // the resolve form's scroll on the terminal (the web page scrolls itself) 2010 fn resolveScroll(self: *This) ?*wgt.Scroll(Widget) { 2011 return switch (self.viewStack().children.values()[form_view_index]) { 2012 .scroll => |*scroll| scroll, 2013 else => null, 2014 }; 2015 } 2016 2017 fn listScroll(self: *This, index: usize) *wgt.Scroll(Widget) { 2018 return &self.resultsBox(index).children.values()[list_index].widget.scroll; 2019 } 2020 2021 fn listBox(self: *This, index: usize) *wgt.Box(Widget) { 2022 return &self.listScroll(index).child.box; 2023 } 2024 2025 fn detail(self: *This, index: usize) *DetailType { 2026 const frame = &self.resultsBox(index).children.values()[detail_index].widget.box; 2027 return &@field(frame.children.values()[0].widget, Data.detail_widget_name); 2028 } 2029 2030 fn window(self: *This, index: usize) *const Window { 2031 if (supports_conflicts and index == conflict_view_index) return &self.data.conflicts; 2032 if (supports_drafts and index == drafts_view_index) return &self.data.drafts; 2033 return self.data.window(splitStatus(index)); 2034 } 2035 2036 fn stackSelectedIndex(self: *This) ?usize { 2037 const stack = self.viewStack(); 2038 const cid = stack.getFocus().child_id orelse return null; 2039 return stack.children.getIndex(cid); 2040 } 2041 2042 // the stack's selected master-detail split (null when the tags view or the 2043 // new-thread form shows). 2044 fn selectedSplitIndex(self: *This) ?usize { 2045 const idx = self.stackSelectedIndex() orelse return null; 2046 return if (idx < status_count or (supports_drafts and idx == drafts_view_index) or idx == conflict_view_index) idx else null; 2047 } 2048 2049 fn detailActive(self: *This, index: usize) bool { 2050 const rb = self.resultsBox(index); 2051 const cid = rb.getFocus().child_id orelse return false; 2052 return rb.children.getIndex(cid) == detail_index; 2053 } 2054 2055 fn headerActive(self: *This) bool { 2056 const cid = self.box.getFocus().child_id orelse return false; 2057 return self.box.children.getIndex(cid) == header_index; 2058 } 2059 2060 fn tagsViewActive(self: *This) bool { 2061 if (self.headerActive()) return false; 2062 return self.stackSelectedIndex() == tags_view_index; 2063 } 2064 2065 fn formViewActive(self: *This) bool { 2066 if (self.headerActive()) return false; 2067 return self.stackSelectedIndex() == form_view_index; 2068 } 2069 2070 // the selected thread's index, or null when a window-navigation row is 2071 // selected (a leading "previous" row shifts the thread rows down by one). 2072 fn selectedThreadIndex(self: *This, index: usize) ?usize { 2073 const lb = self.listBox(index); 2074 const cid = lb.getFocus().child_id orelse return null; 2075 const idx = lb.children.getIndex(cid) orelse return null; 2076 const win = self.window(index); 2077 const lead: usize = if (win.prev_id != null) 1 else 0; 2078 if (idx < lead or idx - lead >= win.items.len) return null; 2079 return idx - lead; 2080 } 2081 2082 pub fn build(self: *This, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2083 self.clearGrid(); 2084 2085 // each header tab maps 1:1 to a stack child by position 2086 if (self.header().getSelectedIndex()) |index| { 2087 const stack = self.viewStack(); 2088 stack.getFocus().child_id = stack.children.keys()[index]; 2089 } 2090 2091 if (self.selectedSplitIndex()) |i| { 2092 // swap the detail pane to the selected thread when it changes. 2093 if (self.selectedThreadIndex(i)) |selected| { 2094 const entry = self.window(i).items[selected]; 2095 const changed = if (self.detail(i).entry) |current| !std.mem.eql(u8, current.id, entry.id) else true; 2096 if (changed) { 2097 try self.detail(i).setEntry(allocator, entry); 2098 } 2099 } 2100 2101 // the selected list row shows a border (the focused TextBox 2102 // upgrades it to a double border itself); the rest stay borderless. 2103 const lb = self.listBox(i); 2104 for (lb.children.keys(), lb.children.values()) |id, *child| { 2105 switch (child.widget) { 2106 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 2107 else => {}, 2108 } 2109 } 2110 2111 // cap the list at list_max_width only while the detail pane fits 2112 // beside it. the box drops the detail when the width can't hold 2113 // both minimums, so when it's that narrow we lift the cap and let 2114 // the list fill the whole width. 2115 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 2116 self.resultsBox(i).children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 2117 2118 // stretch the detail pane across the rest of the width so it fills 2119 // the area rather than shrinking to its content; its scroll fills 2120 // the pane. 2121 if (constraint.max_size.width) |w| { 2122 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = if (both_panes_fit) w - list_max_width else w, .height = null }; 2123 } else { 2124 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 2125 } 2126 } 2127 2128 // refresh the form inputs' entries in the session's focus-id -> input 2129 // map with this frame's addresses, so the web/wasm form handling can 2130 // find them by focus id 2131 if (self.threadForm()) |form| { 2132 const failure = if (self.session.formFeedback(feedback_tag)) |saved| saved.failure else null; 2133 (try formField(form, "title")).options.label = if (failure == .required_title) " title (required) " else " title "; 2134 if (comptime supports_drafts) { 2135 if (formWidget(form, .patch_source)) |source| { 2136 source.field().options.label = 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 "; 2137 const submit = formWidget(form, .submit_button) orelse return error.MissingFormField; 2138 try submit.setLabel(allocator, switch (source.selected) { 2139 .fork => "submit draft", 2140 .branch => "submit patch", 2141 }); 2142 } 2143 (try formField(form, "target_branch")).options.label = 2144 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 "; 2145 } 2146 } 2147 if (self.formBox()) |form| { 2148 const inputs_arena = self.session.arena.allocator(); 2149 for (form.children.values()) |*child| switch (child.widget) { 2150 .text_input => |*ti| try self.session.text_inputs.put(inputs_arena, ti.getFocus().id, ti), 2151 else => {}, 2152 }; 2153 } 2154 2155 try self.box.build(allocator, constraint, root_focus); 2156 } 2157 2158 pub fn input(self: *This, allocator: std.mem.Allocator, raw_key: Key, root_focus: *Focus) !void { 2159 // wheel input moves focus like the arrows 2160 const key: Key = if (raw_key == .mouse and raw_key.mouse.action == .scroll) 2161 (if (raw_key.mouse.action.scroll == .up) .arrow_up else .arrow_down) 2162 else 2163 raw_key; 2164 2165 if (self.headerActive()) { 2166 // down from the tabs re-enters the stack if the selected view has 2167 // something to focus; other keys move the tabs. 2168 if (inp.vertDirection(key) == .down) { 2169 const enterable = if (self.viewStack().getSelected()) |selected| switch (selected.*) { 2170 .tag_flow => |*tf| tf.text_boxes.items.len > 0, 2171 // nothing focusable in the unauthorized view 2172 .unauthorized => false, 2173 else => true, 2174 } else false; 2175 if (enterable) root_focus.setFocus(self.box.children.keys()[stack_index]); 2176 } else { 2177 try self.header().input(allocator, key, root_focus); 2178 } 2179 return; 2180 } 2181 if (self.tagsViewActive()) { 2182 self.tagsViewInput(key, root_focus); 2183 return; 2184 } 2185 if (self.formViewActive()) { 2186 if (confirmation(self.data.view) != null) { 2187 try self.confirmationFormInput(allocator, key, root_focus); 2188 } else if (supports_conflicts and self.data.view == .resolve) { 2189 try self.resolveInput(allocator, key, root_focus); 2190 } else { 2191 try self.formInput(allocator, key, root_focus); 2192 } 2193 return; 2194 } 2195 const i = self.selectedSplitIndex() orelse return; 2196 if (self.detailActive(i)) { 2197 switch (try self.detail(i).inputWithExit(allocator, key, root_focus)) { 2198 .none => {}, 2199 .list => self.focusList(i, root_focus), 2200 .header => self.focusHeader(root_focus), 2201 } 2202 } else { 2203 self.listInput(i, key, root_focus); 2204 } 2205 } 2206 2207 // arrow keys move the tag selection; up from the top row crosses to the 2208 // header tabs. 2209 fn tagsViewInput(self: *This, key: Key, root_focus: *Focus) void { 2210 const tf = self.tagsView(); 2211 const cid = tf.focus.child_id orelse return; 2212 const cur = tf.indexOfFocusId(cid) orelse return; 2213 const count = tf.text_boxes.items.len; 2214 switch (key) { 2215 .arrow_left => if (cur > 0) root_focus.setFocus(tf.text_boxes.items[cur - 1].getFocus().id), 2216 .arrow_right => if (cur + 1 < count) root_focus.setFocus(tf.text_boxes.items[cur + 1].getFocus().id), 2217 .arrow_up => if (tf.rowStep(cur, false)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id) else self.focusHeader(root_focus), 2218 .arrow_down => if (tf.rowStep(cur, true)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id), 2219 .home => root_focus.setFocus(tf.text_boxes.items[0].getFocus().id), 2220 .end => root_focus.setFocus(tf.text_boxes.items[count - 1].getFocus().id), 2221 else => {}, 2222 } 2223 } 2224 2225 fn listInput(self: *This, index: usize, key: Key, root_focus: *Focus) void { 2226 // up/down (and the scroll wheel) move the selection a row; page up/down 2227 // jump a fixed amount. right/Enter cross into the detail pane. up from 2228 // the top row crosses into the header tabs. 2229 if (inp.rowDelta(key, @intCast(self.listBox(index).children.count()))) |delta| { 2230 const lb = self.listBox(index); 2231 const at_top = if (lb.getFocus().child_id) |cid| lb.children.getIndex(cid) == 0 else true; 2232 if (delta < 0 and at_top) return self.focusHeader(root_focus); 2233 moveRowFocus(lb, self.listScroll(index), root_focus, delta); 2234 return; 2235 } 2236 switch (key) { 2237 .enter, .arrow_right => _ = self.detail(index).focusFirst(root_focus), 2238 else => {}, 2239 } 2240 } 2241 2242 fn formInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2243 const form = self.formBox() orelse return; 2244 const cid = form.getFocus().child_id orelse return; 2245 const cur = form.children.getIndex(cid) orelse return; 2246 const child = &form.children.values()[cur]; 2247 2248 if (child.widget == .text_input) { 2249 const text_input = &child.widget.text_input; 2250 if (text_input.options.multiline and try multilineKeepsKey(text_input, allocator, key)) 2251 return child.widget.input(allocator, key, root_focus); 2252 } 2253 2254 const on_submit = child.widget == .submit_button; 2255 switch (key) { 2256 .arrow_up, .back_tab => return if (formStep(form, cur, false)) |i| 2257 root_focus.setFocus(form.children.keys()[i]) 2258 else 2259 self.focusHeader(root_focus), 2260 .arrow_down, .tab => return if (formStep(form, cur, true)) |i| root_focus.setFocus(form.children.keys()[i]), 2261 .enter => if (on_submit) return self.submitForm(allocator), 2262 .mouse => |mouse| if (on_submit) { 2263 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) return self.submitForm(allocator); 2264 }, 2265 else => {}, 2266 } 2267 try child.widget.input(allocator, key, root_focus); 2268 } 2269 2270 fn confirmationFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2271 const form = self.confirmationForm() orelse return; 2272 const child_id = form.getFocus().child_id orelse return; 2273 const index = form.children.getIndex(child_id) orelse return; 2274 switch (key) { 2275 .arrow_up, .back_tab => if (index > 1) 2276 root_focus.setFocus(form.children.keys()[index - 1]) 2277 else 2278 self.focusHeader(root_focus), 2279 .arrow_down, .tab => if (index + 1 < form.children.count()) root_focus.setFocus(form.children.keys()[index + 1]), 2280 .enter => try self.submitConfirmation(allocator, index), 2281 .mouse => |mouse| for (form.children.keys()[1..], 1..) |button_id, button_index| { 2282 if (inp.leftClickOn(root_focus, button_id, mouse)) { 2283 try self.submitConfirmation(allocator, button_index); 2284 break; 2285 } 2286 }, 2287 else => {}, 2288 } 2289 } 2290 2291 // the multiline hunk inputs keep enter and any up/down that has a row to 2292 // move to; enter on a "use this" link is a navigation the host follows 2293 // before this runs. 2294 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2295 const form = self.formBox() orelse return; 2296 const cid = form.getFocus().child_id orelse return; 2297 const cur = form.children.getIndex(cid) orelse return; 2298 const child = &form.children.values()[cur]; 2299 2300 if (child.widget == .text_input) { 2301 const ti = &child.widget.text_input; 2302 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2303 return child.widget.input(allocator, key, root_focus); 2304 } 2305 2306 const on_submit = child.widget == .submit_button; 2307 2308 switch (key) { 2309 .arrow_up, .back_tab => if (formStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2310 .arrow_down, .tab => if (formStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2311 .arrow_left, .arrow_right => switch (child.widget) { 2312 .box => |*row| { 2313 const row_cid = row.getFocus().child_id orelse return; 2314 const row_index = row.children.getIndex(row_cid) orelse return; 2315 if (key == .arrow_left) { 2316 if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); 2317 } else if (row_index + 1 < row.children.count()) { 2318 root_focus.setFocus(row.children.keys()[row_index + 1]); 2319 } 2320 }, 2321 else => try child.widget.input(allocator, key, root_focus), 2322 }, 2323 .enter => if (on_submit) try self.submitResolution(allocator), 2324 .mouse => |mouse| if (on_submit) { 2325 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2326 }, 2327 else => try child.widget.input(allocator, key, root_focus), 2328 } 2329 } 2330 2331 // a multiline input keeps enter and any up/down that has a row to move to 2332 fn multilineKeepsKey(text_input: *wgt.TextInput, allocator: std.mem.Allocator, key: Key) !bool { 2333 return switch (key) { 2334 .enter => true, 2335 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2336 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2337 else => false, 2338 }; 2339 } 2340 2341 // the neighboring form control, skipping spacers and blank rows 2342 fn formStep(form: *wgt.Box(Widget), cur: usize, down: bool) ?usize { 2343 var i = cur; 2344 while (true) { 2345 if (down) { 2346 i += 1; 2347 if (i >= form.children.count()) return null; 2348 } else { 2349 if (i == 0) return null; 2350 i -= 1; 2351 } 2352 const child = &form.children.values()[i]; 2353 if (child.hidden) continue; 2354 switch (child.widget) { 2355 .spacer, .text => continue, 2356 else => return i, 2357 } 2358 } 2359 } 2360 2361 // focus the resolve-form child at `i` (a version row focuses its selected 2362 // child) and keep it visible on the terminal 2363 fn focusResolveChild(self: *This, form: *wgt.Box(Widget), i: usize, root_focus: *Focus) void { 2364 const child = &form.children.values()[i]; 2365 switch (child.widget) { 2366 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2367 else => root_focus.setFocus(form.children.keys()[i]), 2368 } 2369 if (self.session.is_terminal) { 2370 if (self.resolveScroll()) |sc| { 2371 if (child.rect) |rect| sc.scrollToRect(rect); 2372 } 2373 } 2374 } 2375 2376 // re-emit the conflicted thread's event with the resolved content; any 2377 // event on the thread settles its conflict entry. this is the terminal 2378 // path; the web posts the form to the resolve route. 2379 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2380 if (comptime wasm) return; 2381 const io = self.session.io orelse return; 2382 const src = self.data.repo_source orelse return; 2383 const entry = self.data.selectedThread() orelse return; 2384 const author = (try self.session.eventAuthor()) orelse return; 2385 const form = self.formBox() orelse return; 2386 2387 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2388 var title: ?[]u8 = null; 2389 var tags: ?[]u8 = null; 2390 var hunks: std.ArrayList([]const u8) = .empty; 2391 defer { 2392 if (title) |t| allocator.free(t); 2393 if (tags) |t| allocator.free(t); 2394 for (hunks.items) |h| allocator.free(h); 2395 hunks.deinit(allocator); 2396 } 2397 for (form.children.values()) |*child| switch (child.widget) { 2398 .text_input => |*ti| { 2399 const text = try ti.text(allocator); 2400 errdefer allocator.free(text); 2401 if (std.mem.eql(u8, ti.options.name, "title")) { 2402 title = text; 2403 } else if (std.mem.eql(u8, ti.options.name, "tags")) { 2404 tags = text; 2405 } else { 2406 try hunks.append(allocator, text); 2407 } 2408 }, 2409 else => {}, 2410 }; 2411 2412 const id_bytes = try evt.parseEventId(entry.id); 2413 2414 switch (src.repo_kind) { 2415 inline else => |repo_kind| { 2416 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2417 defer any_repo.deinit(io, allocator); 2418 switch (any_repo) { 2419 inline else => |*repo| { 2420 var resolution: Event.Resolve = .{ 2421 .title = title, 2422 .tags = tags, 2423 .hunks = hunks.items, 2424 }; 2425 if (comptime @hasField(Event.Resolve, "theirs")) resolution.theirs = self.data.theirs_picks; 2426 const change = Event.Update{ .resolve = resolution }; 2427 Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 2428 // leave the form up for correction 2429 error.InvalidFields => return, 2430 else => |e| return e, 2431 }; 2432 }, 2433 } 2434 }, 2435 } 2436 2437 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2438 try self.session.navigate(route); 2439 } 2440 2441 // commit a new or edited comment and navigate to its permalink. this is the 2442 // terminal path; the web posts the form to its comment route. 2443 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 2444 if (comptime wasm) return; 2445 const io = self.session.io orelse return; 2446 const src = self.data.repo_source orelse return; 2447 const author = (try self.session.eventAuthor()) orelse return; 2448 const form = self.formBox() orelse return; 2449 const body_input = try formField(form, "body"); 2450 const body = try body_input.text(allocator); 2451 defer allocator.free(body); 2452 if (!evt.Comment.fieldsValid(body)) return; 2453 2454 var thread_id: [evt.event_id_size * 2]u8 = undefined; 2455 @memcpy(&thread_id, self.data.selected_id); 2456 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 2457 var parent: [evt.event_id_size * 2]u8 = undefined; 2458 @memcpy(&parent, self.data.comment_id); 2459 break :blk parent; 2460 }; 2461 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 2462 const editing = self.data.view == .edit_comment; 2463 switch (src.repo_kind) { 2464 inline else => |repo_kind| { 2465 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2466 defer any_repo.deinit(io, allocator); 2467 switch (any_repo) { 2468 inline else => |*repo| if (editing) { 2469 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 2470 try evt.Comment.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &comment_id, body, author); 2471 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 2472 } else { 2473 event_id_hex = try evt.Comment.create(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &parent_id, body, author); 2474 }, 2475 } 2476 }, 2477 } 2478 2479 body_input.clear(allocator); 2480 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 2481 try self.session.navigate(route); 2482 } 2483 2484 // terminal form submissions; the web posts to the forms' routes instead 2485 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 2486 switch (self.data.view) { 2487 .new_comment, .edit_comment => try self.submitComment(allocator), 2488 .edit => try self.submitEditedThread(allocator), 2489 else => try self.submitNewThread(allocator), 2490 } 2491 } 2492 2493 // commit the new thread to the repo's events branch and navigate to it. 2494 // this is the terminal path; the web posts the form to the thread route, 2495 // so the wasm side never runs (or compiles) the repo access below. 2496 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 2497 if (comptime wasm) return; 2498 const io = self.session.io orelse return; 2499 const src = self.data.repo_source orelse return; 2500 const author = (try self.session.eventAuthor()) orelse return; 2501 2502 const form = self.threadForm() orelse return; 2503 const title_input = try formField(form, "title"); 2504 const tags_input = try formField(form, "tags"); 2505 const description_input = try formField(form, "description"); 2506 2507 const title = try title_input.text(allocator); 2508 defer allocator.free(title); 2509 const tags = try tags_input.text(allocator); 2510 defer allocator.free(tags); 2511 const description = try description_input.text(allocator); 2512 defer allocator.free(description); 2513 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 2514 defer if (comptime supports_drafts) allocator.free(target_branch); 2515 2516 if (!Event.fieldsValid(title, tags)) { 2517 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, tags, description, target_branch); 2518 return; 2519 } 2520 2521 if (comptime supports_drafts) { 2522 const source = formWidget(form, .patch_source) orelse return error.MissingFormField; 2523 const source_branch = switch (source.selected) { 2524 .fork => null, 2525 .branch => try source.field().text(allocator), 2526 }; 2527 defer if (source_branch) |branch| allocator.free(branch); 2528 const event_id_hex = Data.create(self.data, self.session, allocator, title, tags, description, target_branch, source_branch) catch |err| { 2529 const failure = FeedbackFailure.fromError(err) orelse return err; 2530 try self.rememberThreadFeedback(failure, title, tags, description, target_branch); 2531 return; 2532 }; 2533 title_input.clear(allocator); 2534 tags_input.clear(allocator); 2535 description_input.clear(allocator); 2536 (try formField(form, "target_branch")).clear(allocator); 2537 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 2538 try self.session.navigate(route); 2539 return; 2540 } 2541 2542 var id_bytes: [evt.event_id_size]u8 = undefined; 2543 io.random(&id_bytes); 2544 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 2545 2546 const event = evt.EventWithId{ 2547 .id = event_id_hex, 2548 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 2549 .author = author, 2550 .event = @unionInit(evt.Event, @tagName(kind), Event{ 2551 .title = title, 2552 .description = description, 2553 .tags = tags, 2554 }), 2555 }; 2556 2557 switch (src.repo_kind) { 2558 inline else => |repo_kind| { 2559 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2560 defer any_repo.deinit(io, allocator); 2561 switch (any_repo) { 2562 inline else => |*repo| try evt.consume(self.session.data.host_kind, .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 2563 } 2564 }, 2565 } 2566 2567 // wipe the form so a return visit starts fresh 2568 title_input.clear(allocator); 2569 tags_input.clear(allocator); 2570 description_input.clear(allocator); 2571 2572 const route = listRoute(self.data.identity, @enumFromInt(0), "", &event_id_hex) orelse return; 2573 try self.session.navigate(route); 2574 } 2575 2576 // re-emit the selected thread's event with the form's content (status 2577 // preserved), then reload the thread's page. this is the terminal path; 2578 // the web posts the form to the edit route. 2579 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 2580 if (comptime wasm) return; 2581 const io = self.session.io orelse return; 2582 const entry = self.data.selectedThread() orelse return; 2583 2584 const form = self.threadForm() orelse return; 2585 const title_input = try formField(form, "title"); 2586 const tags_input = try formField(form, "tags"); 2587 const description_input = try formField(form, "description"); 2588 2589 const title = try title_input.text(allocator); 2590 defer allocator.free(title); 2591 const tags = try tags_input.text(allocator); 2592 defer allocator.free(tags); 2593 const description = try description_input.text(allocator); 2594 defer allocator.free(description); 2595 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 2596 defer if (comptime supports_drafts) allocator.free(target_branch); 2597 2598 if (!Event.fieldsValid(title, tags)) { 2599 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, tags, description, target_branch); 2600 return; 2601 } 2602 const src = self.data.repo_source orelse return; 2603 2604 if (comptime supports_drafts) { 2605 if (entryDraft(entry.*)) { 2606 self.data.editDraft(self.session, allocator, entry.id, title, tags, description, target_branch) catch |err| { 2607 const failure = FeedbackFailure.fromError(err) orelse return err; 2608 try self.rememberThreadFeedback(failure, title, tags, description, target_branch); 2609 return; 2610 }; 2611 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2612 try self.session.navigate(route); 2613 return; 2614 } 2615 } 2616 2617 const id_bytes = try evt.parseEventId(entry.id); 2618 const author = (try self.session.eventAuthor()) orelse return; 2619 2620 switch (src.repo_kind) { 2621 inline else => |repo_kind| { 2622 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2623 defer any_repo.deinit(io, allocator); 2624 switch (any_repo) { 2625 inline else => |*repo| if (supports_drafts) { 2626 Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2627 .title = title, 2628 .tags = tags, 2629 .description = description, 2630 .target_branch = target_branch, 2631 } }, author) catch |err| { 2632 const failure = FeedbackFailure.fromError(err) orelse return err; 2633 try self.rememberThreadFeedback(failure, title, tags, description, target_branch); 2634 return; 2635 }; 2636 } else if (has_status) 2637 try Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2638 .title = title, 2639 .tags = tags, 2640 .description = description, 2641 } }, author) 2642 else 2643 try Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2644 } 2645 }, 2646 } 2647 2648 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2649 try self.session.navigate(route); 2650 } 2651 2652 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, tags: []const u8, description: []const u8, target_branch: []const u8) !void { 2653 const aa = self.session.arena.allocator(); 2654 const source = if (supports_drafts) blk: { 2655 const form = self.threadForm() orelse break :blk null; 2656 break :blk formWidget(form, .patch_source); 2657 } else null; 2658 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 2659 .failure = failure, 2660 .fields = if (comptime supports_drafts) .{ 2661 .title = try aa.dupe(u8, title), 2662 .tags = try aa.dupe(u8, tags), 2663 .description = try aa.dupe(u8, description), 2664 .target_branch = try aa.dupe(u8, target_branch), 2665 .source_branch = if (source) |value| try value.field().text(aa) else "", 2666 .source_kind = if (source) |value| value.selected else .fork, 2667 } else .{ 2668 .title = try aa.dupe(u8, title), 2669 .tags = try aa.dupe(u8, tags), 2670 .description = try aa.dupe(u8, description), 2671 }, 2672 }); 2673 } 2674 2675 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2676 switch (confirmation(self.data.view) orelse return) { 2677 .publish => if (comptime supports_drafts) { 2678 if (comptime wasm) return; 2679 const entry = self.data.selectedThread() orelse return; 2680 if (!entryDraft(entry.*)) return; 2681 try self.data.publishDraft(self.session, allocator, entry.id); 2682 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2683 try self.session.navigate(route); 2684 } else unreachable, 2685 .merge => if (comptime supports_merge) { 2686 if (comptime wasm) return; 2687 const entry = self.data.selectedThread() orelse return; 2688 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 2689 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 2690 self.data.mergePatch(self.session, allocator, entry.id, revision) catch |err| switch (err) { 2691 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 2692 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2693 try self.session.navigate(route); 2694 return; 2695 }, 2696 else => return err, 2697 }; 2698 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2699 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2700 try self.session.navigate(route); 2701 } else unreachable, 2702 .remove => try self.submitRemove(allocator), 2703 } 2704 } 2705 2706 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2707 const comment = self.data.comment_id.len != 0; 2708 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2709 const id = evt.parseEventId(event_id) catch return; 2710 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2711 } 2712 2713 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2714 if (comptime wasm) return; 2715 2716 if (comptime supports_drafts) { 2717 const selected = self.data.selectedThread() orelse return; 2718 if (event_kind == kind and entryDraft(selected.*)) { 2719 try Data.removeDraft(self.session, allocator, &id); 2720 const route = draftsRoute(self.data.identity) orelse return; 2721 try self.session.navigate(route); 2722 return; 2723 } 2724 } 2725 2726 const io = self.session.io orelse return; 2727 const src = self.data.repo_source orelse return; 2728 const author = (try self.session.eventAuthor()) orelse return; 2729 2730 switch (src.repo_kind) { 2731 inline else => |repo_kind| { 2732 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2733 defer any_repo.deinit(io, allocator); 2734 switch (any_repo) { 2735 inline else => |*repo| try evt.remove(self.session.data.host_kind, .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2736 } 2737 }, 2738 } 2739 2740 const id_hex = std.fmt.bytesToHex(id, .lower); 2741 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2742 try self.session.navigate(route); 2743 } 2744 2745 // return to the list. 2746 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2747 root_focus.setFocus(self.listScroll(index).getFocus().id); 2748 } 2749 2750 // cross to the header tabs above the stack. 2751 fn focusHeader(self: *This, root_focus: *Focus) void { 2752 root_focus.setFocus(self.box.children.keys()[header_index]); 2753 } 2754 2755 pub fn clearGrid(self: *This) void { 2756 self.box.clearGrid(); 2757 } 2758 2759 pub fn getGrid(self: This) ?Grid { 2760 return self.box.getGrid(); 2761 } 2762 2763 pub fn getFocus(self: *This) *Focus { 2764 return self.box.getFocus(); 2765 } 2766 2767 // for the parent's "scroll up at the top jumps to the header" check: at the 2768 // top only while the header tabs hold focus, so up from the split 2769 // crosses into the tabs first. 2770 pub fn atTop(self: *This) bool { 2771 return self.headerActive(); 2772 } 2773 }; 2774 } 2775