╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
770 if (self.detailInner().children.count() == 0) return; 771 root_focus.setFocus(self.detailOuter().getFocus().id); 772 } 773 774 // return to the list. 775 fn focusList(self: *View, root_focus: *Focus) void { 776 root_focus.setFocus(self.listScroll().getFocus().id); 777 } 778 779 pub fn clearGrid(self: *View) void { 780 self.box.clearGrid(); 781 } 782 783 pub fn getGrid(self: View) ?Grid { 784 return self.box.getGrid(); 785 } 786 787 pub fn getFocus(self: *View) *Focus { 788 return self.box.getFocus(); 789 } 790 791 fn contentAtTop(self: *View) bool { 792 if (self.detailActive()) { 793 const inner = self.detailInner(); 794 const cid = inner.getFocus().child_id orelse return true; 795 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 796 return first_focused and self.detailScroll().y == 0; 797 } 798 const lb = self.listBox(); 799 const cid = lb.getFocus().child_id orelse return true; 800 return lb.children.getIndex(cid) == 0; 801 } 802 803 // only the header's own row sits directly below the repository header. 804 pub fn atTop(self: *View) bool { 805 if (self.data.no_commits) return true; 806 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 807 return self.headerActive() or (!focusable and self.contentAtTop()); 808 } 809 810 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 811 const header_view = self.header() orelse return false; 812 return header_view.focusHeader(root_focus); 813 } 814 }; 815 816 // the "a:" navigation link for the commits page walking from commit `oid` within 817 // `data.handle.location`. 818 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 819 const route = data.handle.location.commitsRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 820 const url = try route.toUrl(page_arena); 821 return page_arena.allocator().print("a:{s}", .{url}); 822 } 823 824 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 825 // its query) and moves `from` along, so the search box survives paging. a fork 826 // or an object view roots the page at the commit itself. 827 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 828 if (data.handle.location != .repo or data.ref_or_oid == .object) { 829 return data.handle.location.commitsRoute(.object, oid, data.base_oid); 830 } 831 const route = data.handle.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, data.base_oid) orelse return null; 832 const paged = route.withFrom(oid) orelse return null; 833 return paged.withSearch(data.search orelse return paged); 834 } 835 836 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 837 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 838 const url = try route.toUrl(page_arena); 839 return page_arena.allocator().print("a:{s}", .{url}); 840 } 841 842 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 843 // directory, within `location`. 844 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 845 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 846 const url = try route.toUrl(page_arena); 847 return page_arena.allocator().print("a:{s}", .{url}); 848 } 849 850 // the in-page "ai:" anchor for selecting a commit, showing its whole message 851 // when `message` is set. the href is only followed with js off. 852 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, message: bool) ![]const u8 { 853 // a result roots the same results page at its commit, so the query 854 // survives following the row 855 if (data.search != null) { 856 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 857 return page_arena.allocator().print("ai:{s}", .{try route.toUrl(page_arena)}); 858 } 859 const route = (if (message) 860 data.handle.location.commitMessageRoute(.object, commit.oid, data.base_oid) 861 else 862 data.handle.location.commitsRoute(.object, commit.oid, data.base_oid)) orelse return error.RouteTooLong; 863 const url = try route.toUrl(page_arena); 864 return page_arena.allocator().print("ai:{s}", .{url}); 865 } 866 867 // the "a:" link to the page showing `oid`'s message on its own. 868 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 869 const route = data.handle.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 870 const url = try route.toUrl(page_arena); 871 return page_arena.allocator().print("a:{s}", .{url}); 872 } 873