╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
720 self.data.handle.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, self.data.base_oid); 721 try self.session.navigate((route orelse return).withSearch(text) orelse return); 722 } 723 724 fn listInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 725 // up/down (and the scroll wheel) move the selection a row; page up/down 726 // jump a fixed amount. right/Enter cross into the detail pane. Enter/clicks 727 // on the "next" row become navigation in the host before reaching here. 728 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 729 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 730 return; 731 } 732 switch (key) { 733 .enter => if (self.selectedCommitIndex() != null) 734 self.focusDetail(root_focus) 735 else if (self.data.next_start) |next| { 736 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 737 }, 738 .arrow_right => self.focusDetail(root_focus), 739 // when the window is too narrow to lay out the detail pane beside 740 // the list, a click on a row opens it like enter. the row was just 741 // selected, so the detail is swapped to it ahead of the build. 742 .mouse => |mouse| if (self.contentBox().children.values()[detail_index].rect == null and ui.widget.clickOnSelectedRow(self.listBox(), root_focus, mouse)) { 743 try self.refreshDetail(allocator); 744 self.focusDetail(root_focus); 745 }, 746 else => {}, 747 } 748 } 749 750 // enter the detail pane. the host arrives here on right-arrow or Enter from the 751 // list. a pane with no rows can't be entered. setFocus handles the too-narrow 752 // case where the pane isn't laid out yet (it gets selected, then focused after 753 // the next build, landing on its remembered row). 754 fn focusDetail(self: *View, root_focus: *Focus) void { 755 if (self.detailInner().children.count() == 0) return; 756 root_focus.setFocus(self.detailOuter().getFocus().id); 757 } 758 759 // return to the list. 760 fn focusList(self: *View, root_focus: *Focus) void { 761 root_focus.setFocus(self.listScroll().getFocus().id); 762 } 763 764 pub fn clearGrid(self: *View) void { 765 self.box.clearGrid(); 766 } 767 768 pub fn getGrid(self: View) ?Grid { 769 return self.box.getGrid(); 770 } 771 772 pub fn getFocus(self: *View) *Focus { 773 return self.box.getFocus(); 774 } 775 776 fn contentAtTop(self: *View) bool { 777 if (self.detailActive()) { 778 const inner = self.detailInner(); 779 const cid = inner.getFocus().child_id orelse return true; 780 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 781 return first_focused and self.detailScroll().y == 0; 782 } 783 const lb = self.listBox(); 784 const cid = lb.getFocus().child_id orelse return true; 785 return lb.children.getIndex(cid) == 0; 786 } 787 788 // only the header's own row sits directly below the repository header. 789 pub fn atTop(self: *View) bool { 790 if (self.data.no_commits) return true; 791 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 792 return self.headerActive() or (!focusable and self.contentAtTop()); 793 } 794 795 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 796 const header_view = self.header() orelse return false; 797 return header_view.focusHeader(root_focus); 798 } 799 }; 800 801 // the "a:" navigation link for the commits page walking from commit `oid` within 802 // `data.handle.location`. 803 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 804 const route = data.handle.location.commitsRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 805 const url = try route.toUrl(page_arena); 806 return page_arena.allocator().print("a:{s}", .{url}); 807 } 808 809 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 810 // its query) and moves `from` along, so the search box survives paging. a fork 811 // or an object view roots the page at the commit itself. 812 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 813 if (data.handle.location != .repo or data.ref_or_oid == .object) { 814 return data.handle.location.commitsRoute(.object, oid, data.base_oid); 815 } 816 const route = data.handle.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, data.base_oid) orelse return null; 817 const paged = route.withFrom(oid) orelse return null; 818 return paged.withSearch(data.search orelse return paged); 819 } 820 821 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 822 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 823 const url = try route.toUrl(page_arena); 824 return page_arena.allocator().print("a:{s}", .{url}); 825 } 826 827 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 828 // directory, within `location`. 829 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 830 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 831 const url = try route.toUrl(page_arena); 832 return page_arena.allocator().print("a:{s}", .{url}); 833 } 834 835 // the in-page "ai:" anchor for selecting a commit, showing its whole message 836 // when `message` is set. the href is only followed with js off. 837 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, message: bool) ![]const u8 { 838 // a result roots the same results page at its commit, so the query 839 // survives following the row 840 if (data.search != null) { 841 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 842 return page_arena.allocator().print("ai:{s}", .{try route.toUrl(page_arena)}); 843 } 844 const route = (if (message) 845 data.handle.location.commitMessageRoute(.object, commit.oid, data.base_oid) 846 else 847 data.handle.location.commitsRoute(.object, commit.oid, data.base_oid)) orelse return error.RouteTooLong; 848 const url = try route.toUrl(page_arena); 849 return page_arena.allocator().print("ai:{s}", .{url}); 850 } 851 852 // the "a:" link to the page showing `oid`'s message on its own. 853 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 854 const route = data.handle.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 855 const url = try route.toUrl(page_arena); 856 return page_arena.allocator().print("a:{s}", .{url}); 857 } 858