╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
677 tb.getFocus().mode = .all; 678 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 679 } 680 try self.addMessageBox(allocator, inner, commit, .preview); 681 } 682 683 // point the pane at its first row so focus recovery can land here. 684 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 685 686 // reset the scroll to the top for the newly-shown commit: directly on the 687 // terminal (the wasm offset), and via a version bump on the web (so the 688 // renderer's scroll id changes and JS drops the preserved position). 689 const sc = self.detailScroll(); 690 sc.x = 0; 691 sc.y = 0; 692 sc.getFocus().version +%= 1; 693 } 694 695 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 696 if (self.data.no_commits) return self.box.input(allocator, key, root_focus); 697 // scrolling crosses the sub header boundary the same way arrows do 698 const direction = inp.vertDirection(key); 699 if (self.headerActive()) { 700 // active means there is one 701 const header_view = self.header() orelse unreachable; 702 if (direction == .down) { 703 root_focus.setFocus(self.contentBox().getFocus().id); 704 return; 705 } 706 if (key == .enter) if (try header_view.submittedText(allocator)) |text| { 707 defer allocator.free(text); 708 return self.submit(text); 709 }; 710 return header_view.input(allocator, key, root_focus); 711 } 712 if (direction == .up and self.contentAtTop() and self.focusHeader(root_focus)) return; 713 if (self.detailActive()) { 714 const inner = self.detailInner(); 715 if (inp.rowDelta(key, @intCast(inner.children.count()))) |delta| { 716 ui.widget.moveRowFocus(inner, self.detailScroll(), root_focus, delta); 717 } else if (key == .arrow_left) { 718 if (!ui.widget.moveInSelectedRow(inner, root_focus, false)) self.focusList(root_focus); 719 } else if (key == .arrow_right) { 720 _ = ui.widget.moveInSelectedRow(inner, root_focus, true); 721 } 722 } else { 723 try self.listInput(allocator, key, root_focus); 724 } 725 } 726 727 // navigate to the typed query's results, pinned to the list's ref. an 728 // empty query leaves the results for the plain log. 729 fn submit(self: *View, text: []const u8) !void { 730 if (text.len == 0 and self.data.search == null) return; 731 // an object view or a base-bounded list searches the default branch, so the url says so 732 const route = if (self.data.default_branch.len != 0) 733 self.data.handle.location.commitsRoute(.branch, self.data.default_branch, "") 734 else 735 self.data.handle.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, self.data.base_oid); 736 try self.session.navigate((route orelse return).withSearch(text) orelse return); 737 } 738 739 fn listInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 740 // up/down (and the scroll wheel) move the selection a row; page up/down 741 // jump a fixed amount. right/Enter cross into the detail pane. Enter/clicks 742 // on the "next" row become navigation in the host before reaching here. 743 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 744 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 745 return; 746 } 747 switch (key) { 748 .enter => if (self.selectedCommitIndex() != null) 749 self.focusDetail(root_focus) 750 else if (self.data.next_start) |next| { 751 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 752 }, 753 .arrow_right => self.focusDetail(root_focus), 754 // when the window is too narrow to lay out the detail pane beside 755 // the list, a click on a row opens it like enter. the row was just 756 // selected, so the detail is swapped to it ahead of the build. 757 .mouse => |mouse| if (self.contentBox().children.values()[detail_index].rect == null and ui.widget.clickOnSelectedRow(self.listBox(), root_focus, mouse)) { 758 try self.refreshDetail(allocator); 759 self.focusDetail(root_focus); 760 }, 761 else => {}, 762 } 763 } 764 765 // enter the detail pane. the host arrives here on right-arrow or Enter from the 766 // list. a pane with no rows can't be entered. setFocus handles the too-narrow 767 // case where the pane isn't laid out yet (it gets selected, then focused after 768 // the next build, landing on its remembered row). 769 fn focusDetail(self: *View, root_focus: *Focus) void { 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