╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
754 } 755 756 pub fn getGrid(self: View) ?Grid { 757 return self.box.getGrid(); 758 } 759 760 pub fn getFocus(self: *View) *Focus { 761 return self.box.getFocus(); 762 } 763 764 fn contentAtTop(self: *View) bool { 765 if (self.diffActive()) { 766 const inner = self.diffInner(); 767 const cid = inner.getFocus().child_id orelse return true; 768 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 769 return first_focused and self.diffScroll().y == 0; 770 } 771 const lb = self.listBox(); 772 const cid = lb.getFocus().child_id orelse return true; 773 return lb.children.getIndex(cid) == 0; 774 } 775 776 // only the header's own row sits directly below the repository header. 777 pub fn atTop(self: *View) bool { 778 return self.headerActive() or (!self.header().hasFocusable() and self.contentAtTop()); 779 } 780 781 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 782 return self.header().focusHeader(root_focus); 783 } 784 }; 785 786 // the "a:" navigation link for the commits page walking from commit `oid` within 787 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 788 // to `path` ("" = every file). 789 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 790 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 791 const url = try route.toUrl(page_arena); 792 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 793 } 794 795 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 796 // its query) and moves `from` along, so the search box survives paging. a fork 797 // or an object view roots the page at the commit itself. 798 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 799 if (data.location != .repo or data.ref_or_oid == .object) { 800 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 801 } 802 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 803 const paged = route.withFrom(oid) orelse return null; 804 return paged.withSearch(data.search orelse return paged); 805 } 806 807 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 808 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 809 const url = try route.toUrl(page_arena); 810 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 811 } 812 813 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 814 // directory, within `location`. 815 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 816 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 817 const url = try route.toUrl(page_arena); 818 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 819 } 820 821 // the in-page "ai:" anchor for selecting a commit with its current pane content 822 // and window. the href is only followed with js off. 823 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 824 // a result roots the same results page at its commit, so the query 825 // survives following the row 826 if (data.search != null) { 827 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 828 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 829 } 830 const route = (switch (content) { 831 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 832 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 833 }) orelse return error.RouteTooLong; 834 const url = try route.toUrl(page_arena); 835 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 836 } 837 838 // the "a:" link to the page showing `oid`'s message on its own. 839 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 840 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 841 const url = try route.toUrl(page_arena); 842 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 843 } 844