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