╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
478 { 479 var list_scroll = blk: { 480 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert, .stretch = true }); 481 errdefer list_box.deinit(allocator); 482 for (data.commits, 0..) |commit, index| { 483 // an in-page "ai:" anchor so a commit row is clickable with 484 // js off (the browser follows it, rooting the list there); 485 // with wasm the click just selects it and swaps the diff pane. 486 const content = if (index == 0) data.content else Content{ .diff = .{} }; 487 try addRow(allocator, &list_box, firstLine(commit.message), try commitRowLink(session.page_arena, data, commit, content), if (commit.merge) "(merge)" else ""); 488 } 489 if (data.next_start) |next| { 490 try addRow(allocator, &list_box, "next →", try nextPageLink(session.page_arena, data, next), ""); 491 } 492 if (list_box.children.count() > 0) list_box.getFocus().child_id = list_box.children.keys()[0]; 493 break :blk try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 494 }; 495 errdefer list_scroll.deinit(allocator); 496 try box.children.put(allocator, list_scroll.getFocus().id, .{ .widget = .{ .scroll = list_scroll }, .rect = null, .min_size = .{ .width = list_max_width, .height = null }, .max_size = .{ .width = list_max_width, .height = null } }); 497 } 498 499 // the diff pane — a frame around a scroll of the hunks 500 { 501 var diff_outer = blk: { 502 var diff_scroll = try Diff.View.initEmpty(allocator, session); 503 errdefer diff_scroll.deinit(allocator); 504 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .hidden, .direction = .vert }); 505 errdefer frame.deinit(allocator); 506 // the frame's selected child is its scroll, so the focus chain 507 // reaches a hunk (populateDiff points the scroll's inner box at 508 // one), letting focus recovery descend into the diff pane after 509 // it's laid out beside a too-narrow list. 510 frame.getFocus().child_id = diff_scroll.getFocus().id; 511 try frame.children.put(allocator, diff_scroll.getFocus().id, .{ .widget = .{ .diff_view = diff_scroll }, .rect = null, .min_size = null }); 512 break :blk frame; 513 }; 514 errdefer diff_outer.deinit(allocator); 515 diff_outer.getFocus().mode = .mouse; 516 try box.children.put(allocator, diff_outer.getFocus().id, .{ .widget = .{ .box = diff_outer }, .rect = null, .min_size = .{ .width = diff_min_width, .height = null } }); 517 } 518 519 box.getFocus().child_id = box.children.keys()[list_index]; 520 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 521 522 // focus lives in the split, except that search results start in the 523 // search box so the query can be refined right away. 524 outer.getFocus().child_id = outer.children.keys()[if (data.search != null) header_index else outer.children.count() - 1]; 525 526 return .{ 527 .box = outer, 528 .data = data, 529 .session = session, 530 .diffed_index = null, 531 }; 532 } 533 534 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8, bottom_label: []const u8) !void { 535 var row = try wgt.TextBox.init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word, .bottom_label = bottom_label }); 536 errdefer row.deinit(allocator); 537 row.getFocus().mode = .all; 538 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 539 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 540 } 541 542 // a focusable row following the "a:" `link`. 543 fn addLink(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !void { 544 var tb = try wgt.TextBox.init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 545 errdefer tb.deinit(allocator); 546 tb.getFocus().mode = .all; 547 tb.getFocus().kind = .{ .custom = link }; 548 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 549 } 550 551 // how much of the message a pane's box holds: a truncated preview links to 552 // the pane holding the whole thing, which is that link's destination. 553 const MessageBox = enum { preview, whole }; 554 555 // the selected commit's message. 556 fn addMessageBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), commit: Commit, kind: MessageBox) !void { 557 // a truncated message keeps its box even with no whole line to show, 558 // since the box is what links to the whole thing. 559 if (commit.message.len == 0 and !commit.message_truncated) return; 560 const cut_short = commit.message_truncated and kind == .preview; 561 var tb = try messageBox(allocator, commit.message, if (cut_short) " click or press enter to see more " else ""); 562 errdefer tb.deinit(allocator); 563 if (cut_short) tb.getFocus().kind = .{ .custom = try messageLink(self.session.page_arena, self.data, commit.oid) }; 564 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 565 } 566 567 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 568 self.box.deinit(allocator); 569 } 570 571 // the split is last, after the sub-header where there is one 572 fn contentIndex(self: *View) usize { 573 return self.box.children.count() - 1; 574 } 575 576 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 577 return &self.box.children.values()[self.contentIndex()].widget.box; 578 } 579 580 fn header(self: *View) ?*ui.widget.SearchHeader { 581 switch (self.box.children.values()[header_index].widget) { 582 .search_header => |*header_view| return header_view, 583 else => return null, 584 } 585 } 586 587 fn headerActive(self: *View) bool { 588 const header_view = self.header() orelse return false; 589 return self.box.getFocus().child_id == header_view.getFocus().id; 590 } 591 592 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 593 return &self.contentBox().children.values()[list_index].widget.scroll; 594 } 595 596 fn listBox(self: *View) *wgt.Box(ui.Widget) { 597 return &self.listScroll().child.box; 598 } 599 600 fn diffOuter(self: *View) *wgt.Box(ui.Widget) { 601 return &self.contentBox().children.values()[diff_index].widget.box; 602 } 603 604 fn diffScroll(self: *View) *wgt.Scroll(ui.Widget) { 605 return &self.diffOuter().children.values()[0].widget.diff_view.scroll; 606 } 607 608 fn diffInner(self: *View) *wgt.Box(ui.Widget) { 609 return &self.diffScroll().child.box; 610 } 611 612 fn diffActive(self: *View) bool { 613 const content = self.contentBox(); 614 const cid = content.getFocus().child_id orelse return false; 615 return content.children.getIndex(cid) == diff_index; 616 } 617 618 // what the pane shows for the commit at `sel`. the page's content only 619 // applies to the commit it walks from; the rest show their plain diff. 620 fn paneContent(self: *View, sel: usize) Self.Content { 621 return if (sel == 0) self.data.content else .{ .diff = .{} }; 622 } 623 624 // the selected commit's index, or null when the "next" row is selected. 625 fn selectedCommitIndex(self: *View) ?usize { 626 const lb = self.listBox(); 627 const cid = lb.getFocus().child_id orelse return null; 628 const idx = lb.children.getIndex(cid) orelse return null; 629 if (idx >= self.data.commits.len) return null; 630 return idx; 631 } 632 633 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 634 self.clearGrid(); 635 636 // swap the diff pane to the selected commit when it changes. 637 try self.refreshDiff(allocator); 638 639 // the selected list row shows a border (the focused TextBox upgrades it 640 // to a double border itself); the rest stay borderless. 641 const lb = self.listBox(); 642 for (lb.children.keys(), lb.children.values()) |id, *child| { 643 switch (child.widget) { 644 .text_box => |*tb| ui.widget.markSelected(tb, lb.getFocus().child_id == id), 645 else => {}, 646 } 647 } 648 649 // cap the list at list_max_width only while the diff pane fits beside it. 650 // the box drops the diff when the width can't hold both minimums, so when 651 // it's that narrow we lift the cap and let the list fill the whole width. 652 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + diff_min_width else true; 653 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 654 655 // stretch the diff pane across the rest of the width so it fills the area 656 // rather than shrinking to its content; its scroll fills the pane. when 657 // too narrow for both, it fills the whole width. 658 const diff_width: usize = if (constraint.max_size.width) |w| 659 (if (both_panes_fit) w - list_max_width else w) 660 else 661 diff_min_width; 662 self.contentBox().children.values()[diff_index].min_size = .{ .width = diff_width, .height = null }; 663 664 // the message is the pane's only wrapping row, and wrapping needs a 665 // bounded width, which the pane's scroll doesn't grant (it scrolls 666 // horizontally too). cap it to the pane, leaving room for the border 667 // and the scrollbar column. re-capped each build so it tracks resizes. 668 for (self.diffInner().children.values()) |*child| switch (child.widget) { 669 .text_box => |text_box| if (text_box.options.wrap_kind == .word) { 670 child.max_size = .{ .width = diff_width -| 3, .height = null }; 671 }, 672 else => {}, 673 }; 674 675 // the web bounds the layout to the browser viewport like the terminal; 676 // each Scroll's web-native mode hands its full content to a real 677 // scrollable element, so we no longer build unbounded here. 678 // 679 // crossing panes only re-selects the content box's child (focusDiff / 680 // focusList); when the window is too narrow to show both, the pane that 681 // held focus is dropped here. the framework recovers focus after the 682 // top-level build by re-deriving it down the selected-child chain, so 683 // there's nothing to fix up afterward. 684 try self.box.build(allocator, constraint, root_focus); 685 } 686 687 fn refreshDiff(self: *View, allocator: std.mem.Allocator) !void { 688 const sel = self.selectedCommitIndex() orelse return; 689 if (self.diffed_index) |d| if (d == sel) return; 690 try self.populateDiff(allocator, sel); 691 self.diffed_index = sel; 692 } 693 694 fn populateDiff(self: *View, allocator: std.mem.Allocator, sel: usize) !void { 695 const commit = self.data.commits[sel]; 696 const inner = self.diffInner(); 697 698 for (inner.children.values()) |*child| child.widget.deinit(allocator); 699 inner.children.clearAndFree(allocator); 700 inner.getFocus().child_id = null; 701 702 switch (self.paneContent(sel)) { 703 .message => { 704 try addLink(allocator, inner, "← back to diff", try commitsLink(self.session.page_arena, self.data, commit.oid, 0, "")); 705 try self.addMessageBox(allocator, inner, commit, .whole); 706 }, 707 .diff => |d| { 708 if (d.path.len == 0) { 709 try self.addMessageBox(allocator, inner, commit, .preview); 710 if (commit.author != .unknown or commit.committer != .unknown) { 711 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 712 errdefer row.deinit(allocator); 713 if (commit.author != .unknown) { 714 var tb = try ui.authorBox(allocator, self.session.page_arena, commit.author); 715 errdefer tb.deinit(allocator); 716 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 717 } 718 if (commit.committer != .unknown) { 719 var tb = try ui.authorBox(allocator, self.session.page_arena, commit.committer); 720 errdefer tb.deinit(allocator); 721 tb.options.label = " committer "; 722 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 723 } 724 row.getFocus().child_id = row.children.keys()[0]; 725 try inner.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 726 } 727 { 728 var tb = try wgt.TextBox.init(allocator, commit.timestamp, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .label = " timestamp " }); 729 errdefer tb.deinit(allocator); 730 tb.getFocus().mode = .all; 731 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 732 } 733 if (commit.merge) if (self.data.location.commitsMergeRoute(commit.oid)) |route| { 734 try addLink(allocator, inner, "view commits from this merge", try std.fmt.allocPrint(self.session.page_arena.allocator(), "a:{s}", .{try route.toUrl(self.session.page_arena)})); 735 }; 736 if (commit.stats) |stats| { 737 var text: std.Io.Writer.Allocating = .init(allocator); 738 defer text.deinit(); 739 try text.writer.print("lines changed: {d}", .{stats.lines_added + stats.lines_changed}); 740 if (stats.lines_removed != 0) try text.writer.print("\nlines removed: {d}", .{stats.lines_removed}); 741 const bytes_added = stats.bytes_added >= stats.bytes_removed; 742 const bytes = if (bytes_added) stats.bytes_added - stats.bytes_removed else stats.bytes_removed - stats.bytes_added; 743 try text.writer.print("\nbytes {s}: {d}\nfiles changed: {d}", .{ 744 if (bytes_added) "added" else "removed", bytes, stats.files_added + stats.files_changed, 745 }); 746 if (stats.files_removed != 0) try text.writer.print("\nfiles removed: {d}", .{stats.files_removed}); 747 var tb = try wgt.TextBox.init(allocator, text.written(), .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .label = " stats " }); 748 errdefer tb.deinit(allocator); 749 tb.getFocus().mode = .all; 750 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 751 } 752 try addLink(allocator, inner, "view files at this commit", try filesObjectLink(self.session.page_arena, self.data.location, commit.oid)); 753 } 754 755 try (Diff{ 756 .route = .{ .commit = .{ .location = self.data.location, .oid = commit.oid, .base_oid = self.data.base_oid } }, 757 .path = d.path, 758 .window = commit.window, 759 }).appendWindow(allocator, self.session, inner); 760 }, 761 } 762 763 // point the pane at its first row so focus recovery can land here. 764 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 765 766 // reset the scroll to the top for the newly-shown commit: directly on the 767 // terminal (the wasm offset), and via a version bump on the web (so the 768 // renderer's scroll id changes and JS drops the preserved position). 769 const sc = self.diffScroll(); 770 sc.x = 0; 771 sc.y = 0; 772 sc.getFocus().version +%= 1; 773 } 774 775 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 776 // scrolling crosses the sub header boundary the same way arrows do 777 const direction = inp.vertDirection(key); 778 if (self.headerActive()) { 779 // active means there is one 780 const header_view = self.header() orelse unreachable; 781 if (direction == .down) { 782 root_focus.setFocus(self.contentBox().getFocus().id); 783 return; 784 } 785 if (key == .enter) if (try header_view.submittedText(allocator)) |text| { 786 defer allocator.free(text); 787 return self.submit(text); 788 }; 789 return header_view.input(allocator, key, root_focus); 790 } 791 if (direction == .up and self.contentAtTop() and self.focusHeader(root_focus)) return; 792 if (self.diffActive()) { 793 const diff_view = &self.diffOuter().children.values()[0].widget.diff_view; 794 if (key == .arrow_left and self.diffScroll().x == 0) { 795 if (!diff_view.moveInRow(root_focus, false)) self.focusList(root_focus); 796 } else { 797 try diff_view.input(allocator, key, root_focus); 798 } 799 } else { 800 try self.listInput(key, root_focus); 801 } 802 } 803 804 // navigate to the typed query's results, pinned to the list's ref. an 805 // empty query leaves the results for the plain log. 806 fn submit(self: *View, text: []const u8) !void { 807 if (text.len == 0 and self.data.search == null) return; 808 // an object view or a base-bounded list searches the default branch, so the url says so 809 const route = if (self.data.default_branch.len != 0) 810 self.data.location.commitsRoute(.branch, self.data.default_branch, 0, "", "") 811 else 812 self.data.location.commitsRoute(self.data.ref_or_oid, self.data.ref_or_oid_value, 0, "", self.data.base_oid); 813 try self.session.navigate((route orelse return).withSearch(text) orelse return); 814 } 815 816 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 817 // up/down (and the scroll wheel) move the selection a row; page up/down 818 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 819 // on the "next" row become navigation in the host before reaching here. 820 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 821 ui.widget.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 822 return; 823 } 824 switch (key) { 825 .enter => if (self.selectedCommitIndex() != null) 826 self.focusDiff(root_focus) 827 else if (self.data.next_start) |next| { 828 if (pageRoute(self.data, next)) |route| try self.session.navigate(route); 829 }, 830 .arrow_right => self.focusDiff(root_focus), 831 else => {}, 832 } 833 } 834 835 // enter the diff pane. the host arrives here on right-arrow or Enter from the 836 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 837 // case where the pane isn't laid out yet (it gets selected, then focused after 838 // the next build, landing on its remembered hunk). 839 fn focusDiff(self: *View, root_focus: *Focus) void { 840 if (self.diffInner().children.count() == 0) return; 841 root_focus.setFocus(self.diffOuter().getFocus().id); 842 } 843 844 // return to the list. 845 fn focusList(self: *View, root_focus: *Focus) void { 846 root_focus.setFocus(self.listScroll().getFocus().id); 847 } 848 849 pub fn clearGrid(self: *View) void { 850 self.box.clearGrid(); 851 } 852 853 pub fn getGrid(self: View) ?Grid { 854 return self.box.getGrid(); 855 } 856 857 pub fn getFocus(self: *View) *Focus { 858 return self.box.getFocus(); 859 } 860 861 fn contentAtTop(self: *View) bool { 862 if (self.diffActive()) { 863 const inner = self.diffInner(); 864 const cid = inner.getFocus().child_id orelse return true; 865 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 866 return first_focused and self.diffScroll().y == 0; 867 } 868 const lb = self.listBox(); 869 const cid = lb.getFocus().child_id orelse return true; 870 return lb.children.getIndex(cid) == 0; 871 } 872 873 // only the header's own row sits directly below the repository header. 874 pub fn atTop(self: *View) bool { 875 const focusable = if (self.header()) |header_view| header_view.hasFocusable() else false; 876 return self.headerActive() or (!focusable and self.contentAtTop()); 877 } 878 879 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 880 const header_view = self.header() orelse return false; 881 return header_view.focusHeader(root_focus); 882 } 883 }; 884 885 // the "a:" navigation link for the commits page walking from commit `oid` within 886 // `data.location`, windowing the selected commit's diff from hunk `start`, filtered 887 // to `path` ("" = every file). 888 fn commitsLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8, start: usize, path: []const u8) ![]const u8 { 889 const route = data.location.commitsRoute(.object, oid, start, path, data.base_oid) orelse return error.RouteTooLong; 890 const url = try route.toUrl(page_arena); 891 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 892 } 893 894 // this list's page starting at `oid`: a repo's branch or tag keeps its ref (and 895 // its query) and moves `from` along, so the search box survives paging. a fork 896 // or an object view roots the page at the commit itself. 897 fn pageRoute(data: *const Self, oid: []const u8) ?ui.RoutablePage { 898 if (data.location != .repo or data.ref_or_oid == .object) { 899 return data.location.commitsRoute(.object, oid, 0, "", data.base_oid); 900 } 901 const route = data.location.commitsRoute(data.ref_or_oid, data.ref_or_oid_value, 0, "", data.base_oid) orelse return null; 902 const paged = route.withFrom(oid) orelse return null; 903 return paged.withSearch(data.search orelse return paged); 904 } 905 906 fn nextPageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 907 const route = pageRoute(data, oid) orelse return error.RouteTooLong; 908 const url = try route.toUrl(page_arena); 909 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 910 } 911 912 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 913 // directory, within `location`. 914 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, location: ui.RoutablePage.RepoLocation, oid: []const u8) ![]const u8 { 915 const route = location.filesRoute(.object, oid, "", 0) orelse return error.RouteTooLong; 916 const url = try route.toUrl(page_arena); 917 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 918 } 919 920 // the in-page "ai:" anchor for selecting a commit with its current pane content 921 // and window. the href is only followed with js off. 922 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, commit: Commit, content: Content) ![]const u8 { 923 // a result roots the same results page at its commit, so the query 924 // survives following the row 925 if (data.search != null) { 926 const route = pageRoute(data, commit.oid) orelse return error.RouteTooLong; 927 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{try route.toUrl(page_arena)}); 928 } 929 const route = (switch (content) { 930 .message => data.location.commitMessageRoute(.object, commit.oid, data.base_oid), 931 .diff => |diff| data.location.commitsRoute(.object, commit.oid, commit.window.start, diff.path, data.base_oid), 932 }) orelse return error.RouteTooLong; 933 const url = try route.toUrl(page_arena); 934 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 935 } 936 937 // the "a:" link to the page showing `oid`'s message on its own. 938 fn messageLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, oid: []const u8) ![]const u8 { 939 const route = data.location.commitMessageRoute(.object, oid, data.base_oid) orelse return error.RouteTooLong; 940 const url = try route.toUrl(page_arena); 941 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 942 } 943