╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
702 // enter the diff pane by focusing the hunk that was focused last (the box's 703 // child_id remembers it across the trip to the commit list); fall back to the 704 // first hunk on a fresh diff. the host arrives here on right-arrow or Enter 705 // from the list. a diff with no hunks can't be entered. 706 fn focusDiff(self: *View, root_focus: *Focus) !void { 707 const inner = self.diffInner(); 708 if (inner.children.count() == 0) return; 709 const target = inner.getFocus().child_id orelse inner.children.keys()[0]; 710 try root_focus.setFocus(target); 711 if (root_focus.grandchild_id == target) return; 712 // the diff pane wasn't laid out last build (too narrow to show beside 713 // the list), so its hunks aren't in the focus tree yet. select the pane 714 // at the box level, and the hunk will be focused after the next build. 715 self.box.getFocus().child_id = self.diffOuter().getFocus().id; 716 } 717 718 fn focusList(self: *View, root_focus: *Focus) !void { 719 const lb = self.listBox(); 720 const id = lb.getFocus().child_id orelse (if (lb.children.count() > 0) lb.children.keys()[0] else return); 721 try root_focus.setFocus(id); 722 } 723 724 fn moveSelection(self: *View, root_focus: *Focus, delta: isize) !void { 725 const lb = self.listBox(); 726 const keys = lb.children.keys(); 727 if (keys.len == 0) return; 728 const cur_id = lb.getFocus().child_id orelse return; 729 const cur: isize = @intCast(lb.children.getIndex(cur_id) orelse return); 730 const last: isize = @intCast(keys.len - 1); 731 const next: usize = @intCast(std.math.clamp(cur + delta, 0, last)); 732 if (next == @as(usize, @intCast(cur))) return; 733 try root_focus.setFocus(keys[next]); 734 if (lb.children.values()[next].rect) |rect| self.listScroll().scrollToRect(rect); 735 } 736 737 pub fn clearGrid(self: *View) void { 738 self.box.clearGrid(); 739 } 740 741 pub fn getGrid(self: View) ?Grid { 742 return self.box.getGrid(); 743 } 744 745 pub fn getFocus(self: *View) *Focus { 746 return self.box.getFocus(); 747 } 748 749 // for the parent's "scroll up at the top jumps to the header" check. in the 750 // diff pane that means the first hunk is focused and the diff can't scroll up 751 // any further; otherwise up-arrow stays in the pane (scrolling or moving 752 // between hunks). when the list holds focus, report its selection directly. 753 pub fn getSelectedIndex(self: *View) ?usize { 754 if (self.diffActive()) { 755 const inner = self.diffInner(); 756 const cid = inner.getFocus().child_id orelse return 1; 757 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 758 return if (first_focused and self.diffScroll().y == 0) 0 else 1; 759 } 760 const lb = self.listBox(); 761 const cid = lb.getFocus().child_id orelse return null; 762 return lb.children.getIndex(cid); 763 } 764 }; 765 766 // the "a:" navigation link for the commits page starting at `start_oid` within 767 // `identity`, showing the selected commit's first `after` hunks (0 = default). 768 fn commitsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, start_oid: []const u8, after: usize) ![]const u8 { 769 const route = ui.RoutablePage.repoCommitsRoute(identity, start_oid, after) orelse return error.RouteTooLong; 770 const url = try route.urlAlloc(page_arena); 771 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 772 } 773 774 // the in-page "ai:" anchor for selecting `oid` in `identity`'s commit list. it 775 // points at the same route as commitsLink but the "ai:" prefix keeps wasm clicks 776 // in-page (crossPageLink ignores it); the href is only followed with js off. 777 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 778 const route = ui.RoutablePage.repoCommitsRoute(identity, oid, 0) orelse return error.RouteTooLong; 779 const url = try route.urlAlloc(page_arena); 780 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 781 } 782