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