╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
686 // terminal (the wasm offset), and via a version bump on the web (so the 687 // renderer's scroll id changes and JS drops the preserved position). 688 const sc = self.diffScroll(); 689 sc.x = 0; 690 sc.y = 0; 691 sc.getFocus().version +%= 1; 692 } 693 694 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 695 // scrolling crosses the sub header boundary the same way arrows do 696 const direction = inp.vertDirection(key); 697 if (self.headerActive()) { 698 if (direction == .down) { 699 root_focus.setFocus(self.contentBox().getFocus().id); 700 return; 701 } 702 if (key == .enter) if (try self.header().submittedText(allocator)) |text| { 703 defer allocator.free(text); 704 return self.submit(text); 705 }; 706 return self.header().input(allocator, key, root_focus); 707 } 708 if (direction == .up and self.contentAtTop() and self.header().focusHeader(root_focus)) return; 709 if (self.diffActive()) { 710 if (key == .arrow_left and self.diffScroll().x == 0) { 711 self.focusList(root_focus); 712 } else { 713 try self.diffOuter().children.values()[0].widget.diff_view.input(allocator, key, root_focus); 714 } 715 } else { 716 try self.listInput(key, root_focus); 717 } 718 } 719 720 // navigate to the typed query's results, pinned to the list's ref. an 721 // empty query leaves the results for the plain log. 722 fn submit(self: *View, text: []const u8) !void { 723 if (text.len == 0 and self.data.search == null) return; 724 const route = self.data.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, 0, "", self.data.base_oid) orelse return; 725 try self.session.navigate(route.withSearch(text) orelse return); 726 } 727 728 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 729 // up/down (and the scroll wheel) move the selection a row; page up/down 730 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 731 // on the "next" row become navigation in the host before reaching here. 732 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 733 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 734 return; 735 } 736 switch (key) { 737 .enter => if (self.selectedCommitIndex() != null) 738 self.focusDiff(root_focus) 739 else if (self.data.next_start) |next| { 740 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 741 }, 742 .arrow_right => self.focusDiff(root_focus), 743 else => {}, 744 } 745 } 746 747 // enter the diff pane. the host arrives here on right-arrow or Enter from the 748 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 749 // case where the pane isn't laid out yet (it gets selected, then focused after 750 // the next build, landing on its remembered hunk). 751 fn focusDiff(self: *View, root_focus: *Focus) void { 752 if (self.diffInner().children.count() == 0) return; 753 root_focus.setFocus(self.diffOuter().getFocus().id); 754 } 755 756 // return to the list. 757 fn focusList(self: *View, root_focus: *Focus) void { 758 root_focus.setFocus(self.listScroll().getFocus().id); 759 } 760 761 pub fn clearGrid(self: *View) void { 762 self.box.clearGrid(); 763 } 764 765 pub fn getGrid(self: View) ?Grid { 766 return self.box.getGrid(); 767 } 768 769 pub fn getFocus(self: *View) *Focus { 770 return self.box.getFocus(); 771 } 772 773 fn contentAtTop(self: *View) bool { 774 if (self.diffActive()) { 775 const inner = self.diffInner(); 776 const cid = inner.getFocus().child_id orelse return true; 777 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 778 return first_focused and self.diffScroll().y == 0; 779 } 780 const lb = self.listBox(); 781 const cid = lb.getFocus().child_id orelse return true; 782 return lb.children.getIndex(cid) == 0; 783 } 784 785 // only the header's own row sits directly below the repository header. 786 pub fn atTop(self: *View) bool { 787 return self.headerActive() or (!self.header().hasFocusable() and self.contentAtTop()); 788 } 789 790 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 791 return self.header().focusHeader(root_focus); 792 } 793 }; 794 795 // the "a:" navigation link for the commits page walking from commit `oid` within 796 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 797 // to `path` ("" = every file). 798 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 799 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 800 const url = try route.toUrl(page_arena); 801 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 802 } 803 804 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 805 // its query) and moves `from` along, so the search box survives paging. a fork 806 // or an object view roots the page at the commit itself. 807 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 808 if (data.location != .repo or data.ref_or_oid == .object) { 809 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 810 } 811 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 812 const paged = route.withFrom(oid) orelse return null; 813 return paged.withSearch(data.search orelse return paged); 814 } 815 816 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 817 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 818 const url = try route.toUrl(page_arena); 819 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 820 } 821 822 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 823 // directory, within `location`. 824 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 825 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 826 const url = try route.toUrl(page_arena); 827 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 828 } 829 830 // the in-page "ai:" anchor for selecting a commit with its current pane content 831 // and window. the href is only followed with js off. 832 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 833 // a result roots the same results page at its commit, so the query 834 // survives following the row 835 if (data.search != null) { 836 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 837 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 838 } 839 const route = (switch (content) { 840 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 841 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 842 }) orelse return error.RouteTooLong; 843 const url = try route.toUrl(page_arena); 844 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 845 } 846 847 // the "a:" link to the page showing `oid`'s message on its own. 848 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 849 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 850 const url = try route.toUrl(page_arena); 851 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 852 } 853