╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
764 return self.box.getGrid(); 765 } 766 767 pub fn getFocus(self: *View) *Focus { 768 return self.box.getFocus(); 769 } 770 771 fn contentAtTop(self: *View) bool { 772 if (self.diffActive()) { 773 const inner = self.diffInner(); 774 const cid = inner.getFocus().child_id orelse return true; 775 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 776 return first_focused and self.diffScroll().y == 0; 777 } 778 const lb = self.listBox(); 779 const cid = lb.getFocus().child_id orelse return true; 780 return lb.children.getIndex(cid) == 0; 781 } 782 783 // only the header's own row sits directly below the repository header. 784 pub fn atTop(self: *View) bool { 785 return self.headerActive() or (!self.header().hasFocusable() and self.contentAtTop()); 786 } 787 788 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 789 return self.header().focusHeader(root_focus); 790 } 791 }; 792 793 // the "a:" navigation link for the commits page walking from commit `oid` within 794 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 795 // to `path` ("" = every file). 796 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 797 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 798 const url = try route.toUrl(page_arena); 799 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 800 } 801 802 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 803 // its query) and moves `from` along, so the search box survives paging. a fork 804 // or an object view roots the page at the commit itself. 805 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 806 if (data.location != .repo or data.ref_or_oid == .object) { 807 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 808 } 809 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 810 const paged = route.withFrom(oid) orelse return null; 811 return paged.withSearch(data.search orelse return paged); 812 } 813 814 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 815 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 816 const url = try route.toUrl(page_arena); 817 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 818 } 819 820 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 821 // directory, within `location`. 822 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 823 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 824 const url = try route.toUrl(page_arena); 825 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 826 } 827 828 // the in-page "ai:" anchor for selecting a commit with its current pane content 829 // and window. the href is only followed with js off. 830 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 831 // a result roots the same results page at its commit, so the query 832 // survives following the row 833 if (data.search != null) { 834 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 835 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 836 } 837 const route = (switch (content) { 838 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 839 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 840 }) orelse return error.RouteTooLong; 841 const url = try route.toUrl(page_arena); 842 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 843 } 844 845 // the "a:" link to the page showing `oid`'s message on its own. 846 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 847 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 848 const url = try route.toUrl(page_arena); 849 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 850 } 851