╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
787 const keys = lb.children.keys(); 788 if (keys.len == 0) return; 789 const cur_id = lb.getFocus().child_id orelse return; 790 const cur: isize = @intCast(lb.children.getIndex(cur_id) orelse return); 791 const last: isize = @intCast(keys.len - 1); 792 const next: usize = @intCast(std.math.clamp(cur + delta, 0, last)); 793 if (next == @as(usize, @intCast(cur))) return; 794 try root_focus.setFocus(keys[next]); 795 if (lb.children.values()[next].rect) |rect| self.listScroll().scrollToRect(rect); 796 } 797 798 pub fn clearGrid(self: *View) void { 799 self.box.clearGrid(); 800 } 801 802 pub fn getGrid(self: View) ?Grid { 803 return self.box.getGrid(); 804 } 805 806 pub fn getFocus(self: *View) *Focus { 807 return self.box.getFocus(); 808 } 809 810 // for the parent's "scroll up at the top jumps to the header" check. in the 811 // diff pane that means the first hunk is focused and the diff can't scroll up 812 // any further; otherwise up-arrow stays in the pane (scrolling or moving 813 // between hunks). when the list holds focus, report its selection directly. 814 pub fn getSelectedIndex(self: *View) ?usize { 815 if (self.diffActive()) { 816 const inner = self.diffInner(); 817 const cid = inner.getFocus().child_id orelse return 1; 818 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 819 return if (first_focused and self.diffScroll().y == 0) 0 else 1; 820 } 821 const lb = self.listBox(); 822 const cid = lb.getFocus().child_id orelse return null; 823 return lb.children.getIndex(cid); 824 } 825 }; 826 827 // the "a:" navigation link for the commits page walking from commit `oid` within 828 // `identity`, showing the selected commit's first `after` hunks (0 = default). 829 fn commitsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, after: usize) ![]const u8 { 830 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, after) orelse return error.RouteTooLong; 831 const url = try route.urlAlloc(page_arena); 832 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 833 } 834 835 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 836 // directory, within `identity` ("owner/name"). 837 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 838 const route = ui.RoutablePage.repoFilesRoute(identity, .object, oid, "") orelse return error.RouteTooLong; 839 const url = try route.urlAlloc(page_arena); 840 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 841 } 842 843 // the in-page "ai:" anchor for selecting `oid` in `identity`'s commit list. it 844 // points at the same route as commitsLink but the "ai:" prefix keeps wasm clicks 845 // in-page (crossPageLink ignores it); the href is only followed with js off. 846 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 847 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, 0) orelse return error.RouteTooLong; 848 const url = try route.urlAlloc(page_arena); 849 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 850 } 851