╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Threads.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2076 const id_hex = std.fmt.bytesToHex(id, .lower); 2077 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2078 try self.session.navigate(route); 2079 } 2080 2081 // flip the shown issue's status by re-emitting its event, then reload the 2082 // page rooted at the issue so the view reflects the change. this is the 2083 // terminal path; the web posts the button's form to the status route. 2084 fn toggleStatus(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2085 if (comptime !has_status) return; 2086 if (comptime wasm) return; 2087 const io = self.session.io orelse return; 2088 const src = self.data.repo_source orelse return; 2089 const sel = self.detailed_index[index] orelse return; 2090 const entry = self.window(index).items[sel]; 2091 const author = (try self.session.eventAuthor()) orelse return; 2092 2093 const status: Status = switch (entryStatus(entry)) { 2094 .open => .closed, 2095 .closed => .open, 2096 }; 2097 2098 var id_bytes: [evt.event_id_size]u8 = undefined; 2099 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2100 2101 switch (src.repo_kind) { 2102 inline else => |repo_kind| { 2103 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2104 defer any_repo.deinit(io, allocator); 2105 switch (any_repo) { 2106 inline else => |*repo| try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2107 } 2108 }, 2109 } 2110 2111 const route = listRoute(self.data.identity, status, "", entry.id) orelse return; 2112 try self.session.navigate(route); 2113 } 2114 2115 // arrow keys move the tag selection; at the flow's edges focus crosses to 2116 // the neighboring widgets. 2117 fn tagsInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 2118 const tf = self.tagFlow(index) orelse return; 2119 const cid = tf.focus.child_id orelse return; 2120 const cur = tf.indexOfFocusId(cid) orelse return; 2121 const count = tf.text_boxes.items.len; 2122 switch (key) { 2123 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2124 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2125 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2126 self.focusTag(index, tf, root_focus, i); 2127 } else { 2128 _ = self.moveDetailVertical(index, root_focus, false); 2129 }, 2130 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2131 self.focusTag(index, tf, root_focus, i); 2132 } else { 2133 _ = self.moveDetailVertical(index, root_focus, true); 2134 }, 2135 .home => self.focusTag(index, tf, root_focus, 0), 2136 .end => self.focusTag(index, tf, root_focus, count - 1), 2137 else => {}, 2138 } 2139 } 2140 2141 const title_child_index: usize = 0; 2142 const tags_child_index: usize = 2; 2143 2144 // the tool row's first child after the spacer that pushes it right 2145 const first_in_row_index: usize = 1; 2146 2147 fn tagFlow(self: *This, index: usize) ?*ui.TagFlow { 2148 const inner = self.detailInner(index); 2149 if (inner.children.count() <= tags_child_index) return null; 2150 return switch (inner.children.values()[tags_child_index].widget) { 2151 .tag_flow => |*tf| tf, 2152 else => null, 2153 }; 2154 } 2155 2156 fn tagsFocused(self: *This, index: usize) bool { 2157 const inner = self.detailInner(index); 2158 const cid = inner.getFocus().child_id orelse return false; 2159 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2160 } 2161 2162 fn toolRowFocused(self: *This, index: usize) bool { 2163 const outer = self.detailOuter(index); 2164 const cid = outer.getFocus().child_id orelse return false; 2165 return outer.children.getIndex(cid) == tool_row_index; 2166 } 2167 2168 fn focusTag(self: *This, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2169 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2170 // keep the tag visible on the terminal: its rect offset by the flow's 2171 // position in the pane. 2172 if (self.session.is_terminal and item < tf.rects.items.len) { 2173 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2174 var rect = tf.rects.items[item]; 2175 rect.x += flow_rect.x; 2176 rect.y += flow_rect.y; 2177 self.detailScroll(index).scrollToRect(rect); 2178 } 2179 } 2180 } 2181 2182 fn titleFocused(self: *This, index: usize) bool { 2183 const inner = self.detailInner(index); 2184 const cid = inner.getFocus().child_id orelse return false; 2185 return inner.children.getIndex(cid) == title_child_index; 2186 } 2187 2188 fn authorFocused(self: *This, index: usize) bool { 2189 const inner = self.detailInner(index); 2190 const cid = inner.getFocus().child_id orelse return false; 2191 return cid == self.author_id[index]; 2192 } 2193 2194 fn descriptionFocused(self: *This, index: usize) bool { 2195 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2196 return cid == self.description_id[index]; 2197 } 2198 2199 // return to the tool row's last-focused button (the header when the 2200 // description page shows no row). 2201 fn focusToolRow(self: *This, index: usize, root_focus: *Focus) void { 2202 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2203 root_focus.setFocus(cid); 2204 } 2205 2206 // enter the detail pane. an empty pane (no issues) can't be entered. 2207 fn focusDetail(self: *This, index: usize, root_focus: *Focus) !void { 2208 if (self.detailInner(index).children.count() == 0) return; 2209 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2210 } 2211 2212 // return to the list. 2213 fn focusList(self: *This, index: usize, root_focus: *Focus) !void { 2214 root_focus.setFocus(self.listScroll(index).getFocus().id); 2215 } 2216 2217 // cross to the header tabs above the stack. 2218 fn focusHeader(self: *This, root_focus: *Focus) void { 2219 root_focus.setFocus(self.box.children.keys()[header_index]); 2220 } 2221 2222 pub fn clearGrid(self: *This) void { 2223 self.box.clearGrid(); 2224 } 2225 2226 pub fn getGrid(self: This) ?Grid { 2227 return self.box.getGrid(); 2228 } 2229 2230 pub fn getFocus(self: *This) *Focus { 2231 return self.box.getFocus(); 2232 } 2233 2234 // for the parent's "scroll up at the top jumps to the header" check: at the 2235 // top only while the header tabs hold focus, so up from the split 2236 // crosses into the tabs first. 2237 pub fn getSelectedIndex(self: *This) ?usize { 2238 return if (self.headerActive()) 0 else 1; 2239 } 2240 }; 2241 } 2242