╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
817 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 818 // up/down (and the scroll wheel) move the selection a row; page up/down 819 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 820 // on the "next" row become navigation in the host before reaching here. 821 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 822 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 823 return; 824 } 825 switch (key) { 826 .enter => if (self.selectedCommitIndex() != null) 827 self.focusDiff(root_focus) 828 else if (self.data.next_start) |next| { 829 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 830 }, 831 .arrow_right => self.focusDiff(root_focus), 832 else => {}, 833 } 834 } 835 836 // enter the diff pane. the host arrives here on right-arrow or Enter from the 837 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 838 // case where the pane isn't laid out yet (it gets selected, then focused after 839 // the next build, landing on its remembered hunk). 840 fn focusDiff(self: *View, root_focus: *Focus) void { 841 if (self.diffInner().children.count() == 0) return; 842 root_focus.setFocus(self.diffOuter().getFocus().id); 843 } 844 845 // return to the list. 846 fn focusList(self: *View, root_focus: *Focus) void { 847 root_focus.setFocus(self.listScroll().getFocus().id); 848 } 849 850 pub fn clearGrid(self: *View) void { 851 self.box.clearGrid(); 852 } 853 854 pub fn getGrid(self: View) ?Grid { 855 return self.box.getGrid(); 856 } 857 858 pub fn getFocus(self: *View) *Focus { 859 return self.box.getFocus(); 860 } 861 862 fn contentAtTop(self: *View) bool { 863 if (self.diffActive()) { 864 const inner = self.diffInner(); 865 const cid = inner.getFocus().child_id orelse return true; 866 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 867 return first_focused and self.diffScroll().y == 0; 868 } 869 const lb = self.listBox(); 870 const cid = lb.getFocus().child_id orelse return true; 871 return lb.children.getIndex(cid) == 0; 872 } 873 874 // only the header's own row sits directly below the repository header. 875 pub fn atTop(self: *View) bool { 876 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 877 return self.headerActive() or (!focusable and self.contentAtTop()); 878 } 879 880 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 881 const header_view = self.header() orelse return false; 882 return header_view.focusHeader(root_focus); 883 } 884 }; 885 886 // the "a:" navigation link for the commits page walking from commit `oid` within 887 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 888 // to `path` ("" = every file). 889 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 890 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 891 const url = try route.toUrl(page_arena); 892 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 893 } 894 895 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 896 // its query) and moves `from` along, so the search box survives paging. a fork 897 // or an object view roots the page at the commit itself. 898 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 899 if (data.location != .repo or data.ref_or_oid == .object) { 900 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 901 } 902 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 903 const paged = route.withFrom(oid) orelse return null; 904 return paged.withSearch(data.search orelse return paged); 905 } 906 907 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 908 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 909 const url = try route.toUrl(page_arena); 910 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 911 } 912 913 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 914 // directory, within `location`. 915 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 916 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 917 const url = try route.toUrl(page_arena); 918 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 919 } 920 921 // the in-page "ai:" anchor for selecting a commit with its current pane content 922 // and window. the href is only followed with js off. 923 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 924 // a result roots the same results page at its commit, so the query 925 // survives following the row 926 if (data.search != null) { 927 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 928 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 929 } 930 const route = (switch (content) { 931 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 932 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 933 }) orelse return error.RouteTooLong; 934 const url = try route.toUrl(page_arena); 935 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 936 } 937 938 // the "a:" link to the page showing `oid`'s message on its own. 939 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 940 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 941 const url = try route.toUrl(page_arena); 942 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 943 } 944