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