╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Threads.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2024 const cid = form.getFocus().child_id orelse return; 2025 const cur = form.children.getIndex(cid) orelse return; 2026 2027 if (cur == description_field_index) { 2028 const child = &form.children.values()[cur]; 2029 if (try multilineKeepsKey(&child.widget.text_input, allocator, key)) 2030 return child.widget.input(allocator, key, root_focus); 2031 } 2032 2033 switch (key) { 2034 .arrow_up, .back_tab => if (cur > 0) 2035 root_focus.setFocus(form.children.keys()[cur - 1]) 2036 else 2037 self.focusHeader(root_focus), 2038 .arrow_down, .tab => if (cur < submit_field_index) { 2039 root_focus.setFocus(form.children.keys()[cur + 1]); 2040 }, 2041 .enter => if (cur == submit_field_index) try self.submitForm(allocator), 2042 .mouse => |mouse| if (cur == submit_field_index) { 2043 const submit = &form.children.values()[cur].widget.submit_button; 2044 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitForm(allocator); 2045 }, 2046 else => try form.children.values()[cur].widget.input(allocator, key, root_focus), 2047 } 2048 } 2049 2050 fn commentFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2051 const form = self.threadForm() orelse return; 2052 const cid = form.getFocus().child_id orelse return; 2053 const cur = form.children.getIndex(cid) orelse return; 2054 const child = &form.children.values()[cur]; 2055 2056 if (cur == comment_body_field_index and try multilineKeepsKey(&child.widget.text_input, allocator, key)) 2057 return child.widget.input(allocator, key, root_focus); 2058 2059 switch (key) { 2060 .arrow_up, .back_tab => if (cur > comment_author_field_index) 2061 root_focus.setFocus(form.children.keys()[cur - 1]) 2062 else 2063 self.focusHeader(root_focus), 2064 .arrow_down, .tab => if (cur < comment_submit_field_index) 2065 root_focus.setFocus(form.children.keys()[cur + 1]), 2066 .enter => if (cur == comment_submit_field_index) try self.submitComment(allocator), 2067 .mouse => |mouse| if (cur == comment_submit_field_index) { 2068 const submit = &child.widget.submit_button; 2069 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitComment(allocator); 2070 }, 2071 else => try child.widget.input(allocator, key, root_focus), 2072 } 2073 } 2074 2075 fn removeFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2076 const form = self.removeForm() orelse return; 2077 const button_id = form.children.keys()[1]; 2078 switch (key) { 2079 .arrow_up, .back_tab => self.focusHeader(root_focus), 2080 .enter => try self.submitRemove(allocator), 2081 .mouse => |mouse| if (inp.leftClickOn(root_focus, button_id, mouse)) try self.submitRemove(allocator), 2082 else => {}, 2083 } 2084 } 2085 2086 // the multiline hunk inputs keep enter and any up/down that has a row to 2087 // move to; enter on a "use this" link is a navigation the host follows 2088 // before this runs. 2089 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2090 const form = self.threadForm() orelse return; 2091 const cid = form.getFocus().child_id orelse return; 2092 const cur = form.children.getIndex(cid) orelse return; 2093 const child = &form.children.values()[cur]; 2094 2095 if (child.widget == .text_input) { 2096 const ti = &child.widget.text_input; 2097 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2098 return child.widget.input(allocator, key, root_focus); 2099 } 2100 2101 const on_submit = child.widget == .submit_button; 2102 2103 switch (key) { 2104 .arrow_up, .back_tab => if (resolveStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2105 .arrow_down, .tab => if (resolveStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2106 .arrow_left, .arrow_right => switch (child.widget) { 2107 .box => |*row| { 2108 const row_cid = row.getFocus().child_id orelse return; 2109 const row_index = row.children.getIndex(row_cid) orelse return; 2110 if (key == .arrow_left) { 2111 if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); 2112 } else if (row_index + 1 < row.children.count()) { 2113 root_focus.setFocus(row.children.keys()[row_index + 1]); 2114 } 2115 }, 2116 else => try child.widget.input(allocator, key, root_focus), 2117 }, 2118 .enter => if (on_submit) try self.submitResolution(allocator), 2119 .mouse => |mouse| if (on_submit) { 2120 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2121 }, 2122 else => try child.widget.input(allocator, key, root_focus), 2123 } 2124 } 2125 2126 // a multiline input keeps enter and any up/down that has a row to move to 2127 fn multilineKeepsKey(text_input: *wgt.TextInput(ui.Widget), allocator: std.mem.Allocator, key: Key) !bool { 2128 return switch (key) { 2129 .enter => true, 2130 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2131 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2132 else => false, 2133 }; 2134 } 2135 2136 // the neighboring focusable resolve-form child, skipping the spacer and 2137 // the blank gap rows 2138 fn resolveStep(form: *wgt.Box(ui.Widget), cur: usize, down: bool) ?usize { 2139 var i = cur; 2140 while (true) { 2141 if (down) { 2142 i += 1; 2143 if (i >= form.children.count()) return null; 2144 } else { 2145 if (i == 0) return null; 2146 i -= 1; 2147 } 2148 switch (form.children.values()[i].widget) { 2149 .spacer, .text => continue, 2150 else => return i, 2151 } 2152 } 2153 } 2154 2155 // focus the resolve-form child at `i` (a version row focuses its selected 2156 // child) and keep it visible on the terminal 2157 fn focusResolveChild(self: *This, form: *wgt.Box(ui.Widget), i: usize, root_focus: *Focus) void { 2158 const child = &form.children.values()[i]; 2159 switch (child.widget) { 2160 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2161 else => root_focus.setFocus(form.children.keys()[i]), 2162 } 2163 if (self.session.is_terminal) { 2164 if (self.resolveScroll()) |sc| { 2165 if (child.rect) |rect| sc.scrollToRect(rect); 2166 } 2167 } 2168 } 2169 2170 // re-emit the conflicted thread's event with the resolved content; any 2171 // event on the thread settles its conflict entry. this is the terminal 2172 // path; the web posts the form to the resolve route. 2173 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2174 if (comptime wasm) return; 2175 const io = self.session.io orelse return; 2176 const src = self.data.repo_source orelse return; 2177 const entry = self.data.selectedThread() orelse return; 2178 const author = (try self.session.eventAuthor()) orelse return; 2179 const form = self.threadForm() orelse return; 2180 2181 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2182 var title: ?[]u8 = null; 2183 var tags: ?[]u8 = null; 2184 var hunks: std.ArrayList([]const u8) = .empty; 2185 defer { 2186 if (title) |t| allocator.free(t); 2187 if (tags) |t| allocator.free(t); 2188 for (hunks.items) |h| allocator.free(h); 2189 hunks.deinit(allocator); 2190 } 2191 for (form.children.values()) |*child| switch (child.widget) { 2192 .text_input => |*ti| { 2193 const text = try ti.text(allocator); 2194 errdefer allocator.free(text); 2195 if (std.mem.eql(u8, ti.options.name, "title")) { 2196 title = text; 2197 } else if (std.mem.eql(u8, ti.options.name, "tags")) { 2198 tags = text; 2199 } else { 2200 try hunks.append(allocator, text); 2201 } 2202 }, 2203 else => {}, 2204 }; 2205 2206 const id_bytes = try evt.parseEventId(entry.id); 2207 2208 switch (src.repo_kind) { 2209 inline else => |repo_kind| { 2210 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2211 defer any_repo.deinit(io, allocator); 2212 switch (any_repo) { 2213 inline else => |*repo| { 2214 const change: Event.Update = if (comptime kind == .patch) 2215 .{ .resolve = .{ 2216 .title = title, 2217 .tags = tags, 2218 .hunks = hunks.items, 2219 .theirs = self.data.theirs_picks, 2220 } } 2221 else 2222 .{ .resolve = .{ 2223 .title = title, 2224 .tags = tags, 2225 .hunks = hunks.items, 2226 } }; 2227 Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 2228 // leave the form up for correction 2229 error.InvalidFields => return, 2230 else => |e| return e, 2231 }; 2232 }, 2233 } 2234 }, 2235 } 2236 2237 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2238 try self.session.navigate(route); 2239 } 2240 2241 // commit a new or edited comment and navigate to its permalink. this is the 2242 // terminal path; the web posts the form to its comment route. 2243 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 2244 if (comptime wasm) return; 2245 const io = self.session.io orelse return; 2246 const src = self.data.repo_source orelse return; 2247 const author = (try self.session.eventAuthor()) orelse return; 2248 const form = self.threadForm() orelse return; 2249 const body_input = &form.children.values()[comment_body_field_index].widget.text_input; 2250 const body = try body_input.text(allocator); 2251 defer allocator.free(body); 2252 if (!evt.Comment.fieldsValid(body)) return; 2253 2254 var thread_id: [evt.event_id_size * 2]u8 = undefined; 2255 @memcpy(&thread_id, self.data.selected_id); 2256 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 2257 var parent: [evt.event_id_size * 2]u8 = undefined; 2258 @memcpy(&parent, self.data.comment_id); 2259 break :blk parent; 2260 }; 2261 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 2262 const editing = self.data.view == .edit_comment; 2263 switch (src.repo_kind) { 2264 inline else => |repo_kind| { 2265 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2266 defer any_repo.deinit(io, allocator); 2267 switch (any_repo) { 2268 inline else => |*repo| if (editing) { 2269 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 2270 try evt.Comment.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &comment_id, body, author); 2271 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 2272 } else { 2273 event_id_hex = try evt.Comment.create(repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &parent_id, body, author); 2274 }, 2275 } 2276 }, 2277 } 2278 2279 body_input.clear(allocator); 2280 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 2281 try self.session.navigate(route); 2282 } 2283 2284 // the terminal submit paths: the new form commits a new thread event, the 2285 // edit form re-emits the selected thread's event with the form's content. 2286 // the web posts the forms to their routes instead. 2287 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 2288 if (self.data.view == .edit) { 2289 try self.submitEditedThread(allocator); 2290 } else { 2291 try self.submitNewThread(allocator); 2292 } 2293 } 2294 2295 // commit the new thread to the repo's events branch and navigate to it. 2296 // this is the terminal path; the web posts the form to the thread route, 2297 // so the wasm side never runs (or compiles) the repo access below. 2298 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 2299 if (comptime wasm) return; 2300 const io = self.session.io orelse return; 2301 const src = self.data.repo_source orelse return; 2302 const author = (try self.session.eventAuthor()) orelse return; 2303 2304 const form = self.threadForm() orelse return; 2305 const title_input = &form.children.values()[title_field_index].widget.text_input; 2306 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 2307 const description_input = &form.children.values()[description_field_index].widget.text_input; 2308 2309 const title = try title_input.text(allocator); 2310 defer allocator.free(title); 2311 const tags = try tags_input.text(allocator); 2312 defer allocator.free(tags); 2313 const description = try description_input.text(allocator); 2314 defer allocator.free(description); 2315 2316 if (!Event.fieldsValid(title, tags)) return; 2317 2318 if (comptime kind == .patch) { 2319 const event_id_hex = try Data.createDraft(self.data, self.session, allocator, title, tags, description); 2320 title_input.clear(allocator); 2321 tags_input.clear(allocator); 2322 description_input.clear(allocator); 2323 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 2324 try self.session.navigate(route); 2325 return; 2326 } 2327 2328 var id_bytes: [evt.event_id_size]u8 = undefined; 2329 io.random(&id_bytes); 2330 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 2331 2332 const event = evt.EventWithId{ 2333 .id = event_id_hex, 2334 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 2335 .author = author, 2336 .event = @unionInit(evt.Event, @tagName(kind), Event{ 2337 .title = title, 2338 .description = description, 2339 .tags = tags, 2340 }), 2341 }; 2342 2343 switch (src.repo_kind) { 2344 inline else => |repo_kind| { 2345 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2346 defer any_repo.deinit(io, allocator); 2347 switch (any_repo) { 2348 inline else => |*repo| try evt.consume(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 2349 } 2350 }, 2351 } 2352 2353 // wipe the form so a return visit starts fresh 2354 title_input.clear(allocator); 2355 tags_input.clear(allocator); 2356 description_input.clear(allocator); 2357 2358 const route = listRoute(self.data.identity, @enumFromInt(0), "", &event_id_hex) orelse return; 2359 try self.session.navigate(route); 2360 } 2361 2362 // re-emit the selected thread's event with the form's content (status 2363 // preserved), then reload the thread's page. this is the terminal path; 2364 // the web posts the form to the edit route. 2365 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 2366 if (comptime wasm) return; 2367 const io = self.session.io orelse return; 2368 const src = self.data.repo_source orelse return; 2369 const entry = self.data.selectedThread() orelse return; 2370 const author = (try self.session.eventAuthor()) orelse return; 2371 2372 const form = self.threadForm() orelse return; 2373 const title_input = &form.children.values()[title_field_index].widget.text_input; 2374 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 2375 const description_input = &form.children.values()[description_field_index].widget.text_input; 2376 2377 const title = try title_input.text(allocator); 2378 defer allocator.free(title); 2379 const tags = try tags_input.text(allocator); 2380 defer allocator.free(tags); 2381 const description = try description_input.text(allocator); 2382 defer allocator.free(description); 2383 2384 if (!Event.fieldsValid(title, tags)) return; 2385 2386 const id_bytes = try evt.parseEventId(entry.id); 2387 2388 switch (src.repo_kind) { 2389 inline else => |repo_kind| { 2390 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2391 defer any_repo.deinit(io, allocator); 2392 switch (any_repo) { 2393 inline else => |*repo| if (has_status) 2394 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2395 .title = title, 2396 .tags = tags, 2397 .description = description, 2398 } }, author) 2399 else 2400 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2401 } 2402 }, 2403 } 2404 2405 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2406 try self.session.navigate(route); 2407 } 2408 2409 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2410 const comment = self.data.comment_id.len != 0; 2411 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2412 const id = evt.parseEventId(event_id) catch return; 2413 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2414 } 2415 2416 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2417 if (comptime wasm) return; 2418 const io = self.session.io orelse return; 2419 const src = self.data.repo_source orelse return; 2420 const author = (try self.session.eventAuthor()) orelse return; 2421 2422 switch (src.repo_kind) { 2423 inline else => |repo_kind| { 2424 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2425 defer any_repo.deinit(io, allocator); 2426 switch (any_repo) { 2427 inline else => |*repo| try evt.remove(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2428 } 2429 }, 2430 } 2431 2432 const id_hex = std.fmt.bytesToHex(id, .lower); 2433 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2434 try self.session.navigate(route); 2435 } 2436 2437 // flip the shown thread's status by re-emitting its event, then reload the 2438 // page rooted at the thread so the view reflects the change. this is the 2439 // terminal path; the web posts the button's form to the status route. 2440 fn toggleStatus(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2441 if (comptime !has_status) return; 2442 if (comptime wasm) return; 2443 const io = self.session.io orelse return; 2444 const src = self.data.repo_source orelse return; 2445 const sel = self.detailed_index[index] orelse return; 2446 const entry = self.window(index).items[sel]; 2447 const author = (try self.session.eventAuthor()) orelse return; 2448 2449 const status = (statusChange(entryStatus(entry)) orelse return).status; 2450 2451 const id_bytes = try evt.parseEventId(entry.id); 2452 2453 switch (src.repo_kind) { 2454 inline else => |repo_kind| { 2455 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2456 defer any_repo.deinit(io, allocator); 2457 switch (any_repo) { 2458 inline else => |*repo| try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2459 } 2460 }, 2461 } 2462 2463 const route = listRoute(self.data.identity, status, "", entry.id) orelse return; 2464 try self.session.navigate(route); 2465 } 2466 2467 // arrow keys move the tag selection; at the flow's edges focus crosses to 2468 // the neighboring widgets. 2469 fn tagsInput(self: *This, index: usize, child_index: usize, tf: *ui.TagFlow, key: Key, root_focus: *Focus) void { 2470 const cid = tf.focus.child_id orelse return; 2471 const cur = tf.indexOfFocusId(cid) orelse return; 2472 const count = tf.text_boxes.items.len; 2473 switch (key) { 2474 .arrow_left => if (cur > 0) self.focusTag(index, child_index, tf, root_focus, cur - 1) else self.focusList(index, root_focus), 2475 .arrow_right => if (cur + 1 < count) self.focusTag(index, child_index, tf, root_focus, cur + 1), 2476 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2477 self.focusTag(index, child_index, tf, root_focus, i); 2478 } else { 2479 _ = self.moveDetailVertical(index, root_focus, false); 2480 }, 2481 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2482 self.focusTag(index, child_index, tf, root_focus, i); 2483 } else { 2484 _ = self.moveDetailVertical(index, root_focus, true); 2485 }, 2486 .home => self.focusTag(index, child_index, tf, root_focus, 0), 2487 .end => self.focusTag(index, child_index, tf, root_focus, count - 1), 2488 else => {}, 2489 } 2490 } 2491 2492 const title_child_index: usize = 0; 2493 2494 // the tool row's first child after the spacer that pushes it right 2495 const first_in_row_index: usize = 1; 2496 2497 fn toolRowFocused(self: *This, index: usize) bool { 2498 const outer = self.detailOuter(index); 2499 const cid = outer.getFocus().child_id orelse return false; 2500 return outer.children.getIndex(cid) == tool_row_index; 2501 } 2502 2503 fn focusTag(self: *This, index: usize, child_index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2504 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2505 // keep the tag visible on the terminal: its rect offset by the flow's 2506 // position in the pane. 2507 if (self.session.is_terminal and item < tf.rects.items.len) { 2508 if (self.detailInner(index).children.values()[child_index].rect) |flow_rect| { 2509 var rect = tf.rects.items[item]; 2510 rect.x += flow_rect.x; 2511 rect.y += flow_rect.y; 2512 self.detailScroll(index).scrollToRect(rect); 2513 } 2514 } 2515 } 2516 2517 // return to the tool row's last-focused button (the header when the 2518 // description page shows no row). 2519 fn focusToolRow(self: *This, index: usize, root_focus: *Focus) void { 2520 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2521 root_focus.setFocus(cid); 2522 } 2523 2524 // enter the detail pane. an empty pane can't be entered. 2525 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 2526 if (self.detailInner(index).children.count() == 0) return; 2527 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2528 } 2529 2530 // return to the list. 2531 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2532 root_focus.setFocus(self.listScroll(index).getFocus().id); 2533 } 2534 2535 // cross to the header tabs above the stack. 2536 fn focusHeader(self: *This, root_focus: *Focus) void { 2537 root_focus.setFocus(self.box.children.keys()[header_index]); 2538 } 2539 2540 pub fn clearGrid(self: *This) void { 2541 self.box.clearGrid(); 2542 } 2543 2544 pub fn getGrid(self: This) ?Grid { 2545 return self.box.getGrid(); 2546 } 2547 2548 pub fn getFocus(self: *This) *Focus { 2549 return self.box.getFocus(); 2550 } 2551 2552 // for the parent's "scroll up at the top jumps to the header" check: at the 2553 // top only while the header tabs hold focus, so up from the split 2554 // crosses into the tabs first. 2555 pub fn getSelectedIndex(self: *This) ?usize { 2556 return if (self.headerActive()) 0 else 1; 2557 } 2558 }; 2559 } 2560