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