╭ changed ─────────────╮ │src/ui/Repo/Issues.zig│ ╰──────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────╮ │← previous│ ╰──────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────╮ │1614 │ │1615 if (cur == description_field_index) { │ │1616 const child = &form.children.values()[cur]; │ │1152 - const description = &child.widget.text_input; │ │1153 - switch (key) { │ │1154 - .enter => return child.widget.input(allocator, key, root_focus),│ │1155 - .arrow_up => if (!try description.cursorOnFirstRow(allocator)) │ │1156 - return child.widget.input(allocator, key, root_focus), │ │1157 - .arrow_down => if (!try description.cursorOnLastRow(allocator)) │ │1158 - return child.widget.input(allocator, key, root_focus), │ │1159 - else => {}, │ │1160 - } │ │1617 + if (try multilineKeepsKey(&child.widget.text_input, allocator, key))│ │1618 + return child.widget.input(allocator, key, root_focus); │ │1619 } │ │1620 │ │1621 switch (key) { │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1631 try self.submitForm(allocator); │ │1632 }, │ │1633 else => try form.children.values()[cur].widget.input(allocator, key, root_focus), │ │1634 + } │ │1635 + } │ │1636 + │ │1637 + // the multiline hunk inputs keep enter and any up/down that has a row to │ │1638 + // move to; enter on a "use this" link is a navigation the host follows │ │1639 + // before this runs. │ │1640 + fn resolveInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { │ │1641 + const form = self.issueForm() orelse return; │ │1642 + const cid = form.getFocus().child_id orelse return; │ │1643 + const cur = form.children.getIndex(cid) orelse return; │ │1644 + const child = &form.children.values()[cur]; │ │1645 + │ │1646 + if (child.widget == .text_input) { │ │1647 + const ti = &child.widget.text_input; │ │1648 + if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) │ │1649 + return child.widget.input(allocator, key, root_focus); │ │1650 + } │ │1651 + │ │1652 + const on_submit = isSubmitButton(&child.widget); │ │1653 + │ │1654 + switch (key) { │ │1655 + .arrow_up, .back_tab => if (resolveStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus),│ │1656 + .arrow_down, .tab => if (resolveStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), │ │1657 + .arrow_left, .arrow_right => switch (child.widget) { │ │1658 + .box => |*row| { │ │1659 + const row_cid = row.getFocus().child_id orelse return; │ │1660 + const row_index = row.children.getIndex(row_cid) orelse return; │ │1661 + if (key == .arrow_left) { │ │1662 + if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); │ │1663 + } else if (row_index + 1 < row.children.count()) { │ │1664 + root_focus.setFocus(row.children.keys()[row_index + 1]); │ │1665 + } │ │1666 + }, │ │1667 + else => try child.widget.input(allocator, key, root_focus), │ │1668 + }, │ │1669 + .enter => if (on_submit) try self.submitResolution(allocator), │ │1670 + .mouse => |mouse| if (on_submit and inp.leftClickOn(root_focus, cid, mouse)) { │ │1671 + try self.submitResolution(allocator); │ │1672 + } else if (mouse.action == .scroll) { │ │1673 + if (self.resolveScroll()) |sc| { │ │1674 + sc.y += if (mouse.action.scroll == .up) @as(isize, -1) else 1; │ │1675 + sc.clampToContent(); │ │1676 + } │ │1677 + }, │ │1678 + else => try child.widget.input(allocator, key, root_focus), │ │1679 + } │ │1680 + } │ │1681 + │ │1682 + // a multiline input keeps enter and any up/down that has a row to move to │ │1683 + fn multilineKeepsKey(text_input: *wgt.TextInput(ui.Widget), allocator: std.mem.Allocator, key: Key) !bool { │ │1684 + return switch (key) { │ │1685 + .enter => true, │ │1686 + .arrow_up => !try text_input.cursorOnFirstRow(allocator), │ │1687 + .arrow_down => !try text_input.cursorOnLastRow(allocator), │ │1688 + else => false, │ │1689 + }; │ │1690 + } │ │1691 + │ │1692 + // whether the widget is a button that posts its form │ │1693 + fn isSubmitButton(widget: *const ui.Widget) bool { │ │1694 + return switch (widget.*) { │ │1695 + .text_box => |*tb| switch (tb.box.focus.kind) { │ │1696 + .custom => |custom| std.mem.eql(u8, custom, "submit"), │ │1697 + else => false, │ │1698 + }, │ │1699 + else => false, │ │1700 + }; │ │1701 + } │ │1702 + │ │1703 + // the neighboring focusable resolve-form child, skipping the spacer and │ │1704 + // the blank gap rows │ │1705 + fn resolveStep(form: *wgt.Box(ui.Widget), cur: usize, down: bool) ?usize { │ │1706 + var i = cur; │ │1707 + while (true) { │ │1708 + if (down) { │ │1709 + i += 1; │ │1710 + if (i >= form.children.count()) return null; │ │1711 + } else { │ │1712 + if (i == 0) return null; │ │1713 + i -= 1; │ │1714 + } │ │1715 + switch (form.children.values()[i].widget) { │ │1716 + .spacer, .text => continue, │ │1717 + else => return i, │ │1718 + } │ │1719 + } │ │1720 + } │ │1721 + │ │1722 + // focus the resolve-form child at `i` (a version row focuses its selected │ │1723 + // child) and keep it visible on the terminal │ │1724 + fn focusResolveChild(self: *View, form: *wgt.Box(ui.Widget), i: usize, root_focus: *Focus) void { │ │1725 + const child = &form.children.values()[i]; │ │1726 + switch (child.widget) { │ │1727 + .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), │ │1728 + else => root_focus.setFocus(form.children.keys()[i]), │ │1729 + } │ │1730 + if (self.session.is_terminal) { │ │1731 + if (self.resolveScroll()) |sc| { │ │1732 + if (child.rect) |rect| sc.scrollToRect(rect); │ │1733 + } │ │1734 + } │ │1735 + } │ │1736 + │ │1737 + // re-emit the conflicted issue's event with the resolved content; any │ │1738 + // event on the issue settles its conflict entry. this is the terminal │ │1739 + // path; the web posts the form to the resolve route. │ │1740 + fn submitResolution(self: *View, allocator: std.mem.Allocator) !void { │ │1741 + if (comptime wasm) return; │ │1742 + const io = self.session.io orelse return; │ │1743 + const src = self.data.repo_source orelse return; │ │1744 + const entry = self.data.selectedIssue() orelse return; │ │1745 + const author_email = (try self.session.eventAuthorEmail()) orelse return; │ │1746 + const form = self.issueForm() orelse return; │ │1747 + │ │1748 + // gather the inputs by name; the d<n> hunk inputs appear in chunk order │ │1749 + var title: ?[]u8 = null; │ │1750 + var tags: ?[]u8 = null; │ │1751 + var hunks: std.ArrayList([]const u8) = .empty; │ │1752 + defer { │ │1753 + if (title) |t| allocator.free(t); │ │1754 + if (tags) |t| allocator.free(t); │ │1755 + for (hunks.items) |h| allocator.free(h); │ │1756 + hunks.deinit(allocator); │ │1757 + } │ │1758 + for (form.children.values()) |*child| switch (child.widget) { │ │1759 + .text_input => |*ti| { │ │1760 + const text = try ti.text(allocator); │ │1761 + errdefer allocator.free(text); │ │1762 + if (std.mem.eql(u8, ti.options.name, "title")) { │ │1763 + title = text; │ │1764 + } else if (std.mem.eql(u8, ti.options.name, "tags")) { │ │1765 + tags = text; │ │1766 + } else { │ │1767 + try hunks.append(allocator, text); │ │1768 + } │ │1769 + }, │ │1770 + else => {}, │ │1771 + }; │ │1772 + │ │1773 + var id_bytes: [evt.event_id_size]u8 = undefined; │ │1774 + _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); │ │1775 + │ │1776 + switch (src.repo_kind) { │ │1777 + inline else => |repo_kind| { │ │1778 + var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); │ │1779 + defer any_repo.deinit(io, allocator); │ │1780 + switch (any_repo) { │ │1781 + inline else => |*repo| evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .resolve = .{ │ │1782 + .title = title, │ │1783 + .tags = tags, │ │1784 + .hunks = hunks.items, │ │1785 + } }, author_email) catch |err| switch (err) { │ │1786 + // leave the form up for correction │ │1787 + error.InvalidFields => return, │ │1788 + else => |e| return e, │ │1789 + }, │ │1790 + } │ │1791 + }, │ │1792 } │ │1793 + │ │1794 + const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.event.status, "", entry.id) orelse return; │ │1795 + try self.session.navigate(route); │ │1796 } │ │1797 │ │1798 // the terminal submit paths: the new form commits a new-issue event, the │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1986 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null;│ │1987 } │ │1988 │ │1370 - // the open/close button inside the detail frame's tool row. the full row │ │1371 - // is spacer + open/close + edit; a logged-out session's row has no │ │1372 - // open/close button, and the description page has no row at all. │ │1989 + // the open/close button inside the detail frame's tool row; a logged-out │ │1990 + // session's or conflicted issue's row has none. │ │1991 fn statusButton(self: *View, index: usize) ?*wgt.TextBox(ui.Widget) { │ │1992 const row = self.toolRow(index); │ │1375 - if (row.children.count() != 3) return null; │ │1376 - return &row.children.values()[button_in_row_index].widget.text_box; │ │1993 + if (row.children.count() <= button_in_row_index) return null; │ │1994 + const child = &row.children.values()[button_in_row_index].widget; │ │1995 + if (!isSubmitButton(child)) return null; │ │1996 + return &child.text_box; │ │1997 } │ │1998 │ │1999 fn toolRowFocused(self: *View, index: usize) bool { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2119 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; │ │2120 const url = try route.toUrl(page_arena); │ │2121 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); │ │2122 +} │ │2123 + │ │2124 +// the "a:" link to the window `status_maybe` names, keeping the tag filter, │ │2125 +// or the conflicts window when null, rooted at issue `id`. │ │2126 +fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?evt.Issue.Status, id: []const u8) ![]const u8 {│ │2127 + if (status_maybe) |status| return issuesLink(page_arena, data.identity, status, data.tag, id); │ │2128 + return conflictsLink(page_arena, data.identity, id); │ │2129 +} │ │2130 + │ │2131 +// the "a:" link to the conflicts list rooted at issue `start` ("" = the │ │2132 +// first window). │ │2133 +fn conflictsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, start: []const u8) ![]const u8 { │ │2134 + const route = ui.RoutablePage.repoIssuesConflictsRoute(identity, start) orelse return error.RouteTooLong; │ │2135 + const url = try route.toUrl(page_arena); │ │2136 + return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); │ │2137 } │ │2138 │ │2139 // the "a:" link to the whole-description page of issue `id` within `identity`. │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2170 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; │ │2171 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); │ │2172 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); │ │1538 - var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none });│ │1539 - errdefer text_box.deinit(allocator); │ │1540 - text_box.getFocus().focusable = true; │ │1541 - text_box.getFocus().kind = .{ .custom = link }; │ │1542 - try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │1543 - try box.children.put(allocator, text_box.getFocus().id, .{ │ │1544 - .widget = .{ .text_box = text_box }, │ │1545 - .rect = null, │ │1546 - .min_size = .{ .width = label.len + 2, .height = null }, │ │1547 - }); │ │2173 + try addTab(allocator, &box, &tab_ids, label, link); │ │2174 } │ │2175 │ │2176 // tags tab, labeled with the active tag filter │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2181 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); │ │2182 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); │ │2183 }; │ │1558 - var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none });│ │1559 - errdefer text_box.deinit(allocator); │ │1560 - text_box.getFocus().focusable = true; │ │1561 - text_box.getFocus().kind = .{ .custom = tags_link }; │ │1562 - try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │1563 - try box.children.put(allocator, text_box.getFocus().id, .{ │ │1564 - .widget = .{ .text_box = text_box }, │ │1565 - .rect = null, │ │1566 - .min_size = .{ .width = label.len + 2, .height = null }, │ │1567 - }); │ │2184 + try addTab(allocator, &box, &tab_ids, label, tags_link); │ │2185 } │ │2186 │ │1570 - // new-issue tab; an edit url shows the edit tab in its place │ │2187 + // new-issue tab; an edit or resolve url shows its tab in this place │ │2188 { │ │1572 - const route = if (data.view == .edit) │ │1573 - ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong │ │1574 - else │ │1575 - ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong; │ │2189 + const route = switch (data.view) { │ │2190 + .edit => ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, │ │2191 + .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong,│ │2192 + else => ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong, │ │2193 + }; │ │2194 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); │ │1577 - const label: []const u8 = if (data.view == .edit) "edit" else "new"; │ │1578 - var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none });│ │1579 - errdefer text_box.deinit(allocator); │ │1580 - text_box.getFocus().focusable = true; │ │1581 - text_box.getFocus().kind = .{ .custom = link }; │ │1582 - try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │1583 - try box.children.put(allocator, text_box.getFocus().id, .{ │ │1584 - .widget = .{ .text_box = text_box }, │ │1585 - .rect = null, │ │1586 - .min_size = .{ .width = label.len + 2, .height = null }, │ │1587 - }); │ │2195 + const label: []const u8 = switch (data.view) { │ │2196 + .edit => "edit", │ │2197 + .resolve => "resolve", │ │2198 + else => "new", │ │2199 + }; │ │2200 + try addTab(allocator, &box, &tab_ids, label, link); │ │2201 + } │ │2202 + │ │2203 + // conflicts tab, labeled with the conflict count │ │2204 + if (data.conflicts.count > 0) { │ │2205 + const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; │ │2206 + const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); │ │2207 + const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); │ │2208 + try addTab(allocator, &box, &tab_ids, label, link); │ │2209 } │ │2210 │ │2211 var self = Header{ .box = box, .tab_ids = tab_ids }; │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │2214 return self; │ │2215 } │ │2216 │ │2217 + fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void {│ │2218 + var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); │ │2219 + errdefer text_box.deinit(allocator); │ │2220 + text_box.getFocus().focusable = true; │ │2221 + text_box.getFocus().kind = .{ .custom = link }; │ │2222 + try tab_ids.put(allocator, text_box.getFocus().id, {}); │ │2223 + try box.children.put(allocator, text_box.getFocus().id, .{ │ │2224 + .widget = .{ .text_box = text_box }, │ │2225 + .rect = null, │ │2226 + .min_size = .{ .width = label.len + 2, .height = null }, │ │2227 + }); │ │2228 + } │ │2229 + │ │2230 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { │ │2231 self.box.deinit(allocator); │ │2232 self.tab_ids.deinit(allocator); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯