╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
752 }, 753 .arrow_right => self.focusDetail(root_focus), 754 else => {}, 755 } 756 } 757 758 // enter the detail pane. the host arrives here on right-arrow or Enter from the 759 // list. a pane with no rows can't be entered. setFocus handles the too-narrow 760 // case where the pane isn't laid out yet (it gets selected, then focused after 761 // the next build, landing on its remembered row). 762 fn focusDetail(self: *View, root_focus: *Focus) void { 763 if (self.detailInner().children.count() == 0) return; 764 root_focus.setFocus(self.detailOuter().getFocus().id); 765 } 766 767 // return to the list. 768 fn focusList(self: *View, root_focus: *Focus) void { 769 root_focus.setFocus(self.listScroll().getFocus().id); 770 } 771 772 pub fn clearGrid(self: *View) void { 773 self.box.clearGrid(); 774 } 775 776 pub fn getGrid(self: View) ?Grid { 777 return self.box.getGrid(); 778 } 779 780 pub fn getFocus(self: *View) *Focus { 781 return self.box.getFocus(); 782 } 783 784 fn contentAtTop(self: *View) bool { 785 if (self.detailActive()) { 786 const inner = self.detailInner(); 787 const cid = inner.getFocus().child_id orelse return true; 788 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 789 return first_focused and self.detailScroll().y == 0; 790 } 791 const lb = self.listBox(); 792 const cid = lb.getFocus().child_id orelse return true; 793 return lb.children.getIndex(cid) == 0; 794 } 795 796 // only the header's own row sits directly below the repository header. 797 pub fn atTop(self: *View) bool { 798 if (self.data.no_commits) return true; 799 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 800 return self.headerActive() or (!focusable and self.contentAtTop()); 801 } 802 803 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 804 const header_view = self.header() orelse return false; 805 return header_view.focusHeader(root_focus); 806 } 807 }; 808 809 // the "a:" navigation link for the commits page walking from commit `oid` within 810 // `data.handle.location`. 811 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 812 const route = data.handle.location.commitsRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 813 const url = try route.toUrl(page_arena); 814 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 815 } 816 817 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 818 // its query) and moves `from` along, so the search box survives paging. a fork 819 // or an object view roots the page at the commit itself. 820 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 821 if (data.handle.location != .repo or data.ref_or_oid == .object) { 822 return data.handle.location.commitsRoute(.object, oid, data.base_oid); 823 } 824 const route = data.handle.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, data.base_oid) orelse return null; 825 const paged = route.withFrom(oid) orelse return null; 826 return paged.withSearch(data.search orelse return paged); 827 } 828 829 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 830 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 831 const url = try route.toUrl(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 `location`. 837 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 838 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 839 const url = try route.toUrl(page_arena); 840 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 841 } 842 843 // the in-page "ai:" anchor for selecting a commit, showing its whole message 844 // when `message` is set. the href is only followed with js off. 845 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, message: bool) ![]const u8 { 846 // a result roots the same results page at its commit, so the query 847 // survives following the row 848 if (data.search != null) { 849 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 850 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 851 } 852 const route = (if (message) 853 data.handle.location.commitMessageRoute(.object, commit.oid, data.base_oid) 854 else 855 data.handle.location.commitsRoute(.object, commit.oid, data.base_oid)) orelse return error.RouteTooLong; 856 const url = try route.toUrl(page_arena); 857 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 858 } 859 860 // the "a:" link to the page showing `oid`'s message on its own. 861 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 862 const route = data.handle.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 863 const url = try route.toUrl(page_arena); 864 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 865 } 866