╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
392 errdefer frame.deinit(allocator); 393 // the frame's selected child is its scroll, so the focus chain 394 // reaches a hunk (populateDiff points the scroll's inner box at 395 // one), letting focus recovery descend into the diff pane after 396 // it's laid out beside a too-narrow list. 397 frame.getFocus().child_id = diff_scroll.getFocus().id; 398 try frame.children.put(allocator, diff_scroll.getFocus().id, .{ .widget = .{ .scroll = diff_scroll }, .rect = null, .min_size = null }); 399 break :blk frame; 400 }; 401 errdefer diff_outer.deinit(allocator); 402 try box.children.put(allocator, diff_outer.getFocus().id, .{ .widget = .{ .box = diff_outer }, .rect = null, .min_size = .{ .width = diff_min_width, .height = null } }); 403 } 404 405 box.getFocus().child_id = box.children.keys()[list_index]; 406 try outer.children.put(allocator, box.getFocus().id, .{ .widget = .{ .box = box }, .rect = null, .min_size = null }); 407 408 // focus lives in the split; the banner isn't focusable. 409 outer.getFocus().child_id = outer.children.keys()[content_index]; 410 411 return .{ 412 .box = outer, 413 .data = data, 414 .session = session, 415 .diffed_index = null, 416 }; 417 } 418 419 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, link: []const u8) !void { 420 var row = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word }); 421 errdefer row.deinit(allocator); 422 row.getFocus().focusable = true; 423 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 424 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 425 } 426 427 // one hunk as a focusable multi-line text box. its lines sit flush (the 428 // inner Text rows have no border); the box's hidden border reserves the 429 // space the double border occupies when focused, so focusing doesn't shift 430 // layout. `lines` are joined into the page arena (text_box borrows it). 431 fn addHunkBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), lines: []const []const u8) !void { 432 if (lines.len == 0) return; 433 const text = try std.mem.join(self.session.page_arena.allocator(), "\n", lines); 434 var tb = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .none }); 435 errdefer tb.deinit(allocator); 436 tb.getFocus().focusable = true; 437 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 438 } 439 440 // a focusable file-path label shown above the first hunk of each file. 441 fn addPathBox(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), path: []const u8) !void { 442 _ = self; 443 var tb = try wgt.TextBox(ui.Widget).init(allocator, path, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .none }); 444 errdefer tb.deinit(allocator); 445 tb.getFocus().focusable = true; 446 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 447 } 448 449 // a focusable window-navigation row ("previous"/"next"). it's a link to this 450 // commit's route at `target_after`, so activating it (the host follows the 451 // "a:" link) reloads the page on the adjacent window — same on TUI and web. 452 fn addNavLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, oid: []const u8, target_after: usize) !void { 453 const link = try commitsLink(self.session.page_arena, self.data.identity, oid, target_after); 454 var tb = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .none }); 455 errdefer tb.deinit(allocator); 456 tb.getFocus().focusable = true; 457 tb.getFocus().kind = .{ .custom = link }; 458 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 459 } 460 461 // a focusable row for the top of the diff pane linking to the files tab at 462 // this commit's tree, so its files are always viewable as of this object. 463 fn addViewFilesLink(self: *View, allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), oid: []const u8) !void { 464 const link = try filesObjectLink(self.session.page_arena, self.data.identity, oid); 465 var tb = try wgt.TextBox(ui.Widget).init(allocator, "view files at this commit", .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .none }); 466 errdefer tb.deinit(allocator); 467 tb.getFocus().focusable = true; 468 tb.getFocus().kind = .{ .custom = link }; 469 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 470 } 471 472 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 473 self.box.deinit(allocator); 474 } 475 476 fn contentBox(self: *View) *wgt.Box(ui.Widget) { 477 return &self.box.children.values()[content_index].widget.box; 478 } 479 480 fn listScroll(self: *View) *wgt.Scroll(ui.Widget) { 481 return &self.contentBox().children.values()[list_index].widget.scroll; 482 } 483 484 fn listBox(self: *View) *wgt.Box(ui.Widget) { 485 return &self.listScroll().child.box; 486 } 487 488 fn diffOuter(self: *View) *wgt.Box(ui.Widget) { 489 return &self.contentBox().children.values()[diff_index].widget.box; 490 } 491 492 fn diffScroll(self: *View) *wgt.Scroll(ui.Widget) { 493 return &self.diffOuter().children.values()[0].widget.scroll; 494 } 495 496 fn diffInner(self: *View) *wgt.Box(ui.Widget) { 497 return &self.diffScroll().child.box; 498 } 499 500 fn diffActive(self: *View) bool { 501 const content = self.contentBox(); 502 const cid = content.getFocus().child_id orelse return false; 503 return content.children.getIndex(cid) == diff_index; 504 } 505 506 // the selected commit's index, or null when the "next" row is selected. 507 fn selectedCommitIndex(self: *View) ?usize { 508 const lb = self.listBox(); 509 const cid = lb.getFocus().child_id orelse return null; 510 const idx = lb.children.getIndex(cid) orelse return null; 511 if (idx >= self.data.commits.len) return null; 512 return idx; 513 } 514 515 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 516 self.clearGrid(); 517 518 // swap the diff pane to the selected commit when it changes. 519 try self.refreshDiff(allocator); 520 521 // mirror the focused commit into the url so it updates as the selection 522 // moves, but only while focus is inside this view (the list or diff). when 523 // focus sits on the header tab, use the page's base /commits route. 524 if (root_focus.grandchild_id) |g| { 525 if (self.box.getFocus().children.contains(g)) { 526 if (self.selectedCommitIndex()) |sel| { 527 // mirror the commit's current diff window so the url stays 528 // linkable (0 for any commit but the windowed start one). 529 if (ui.RoutablePage.repoCommitsRoute(self.data.identity, .object, self.data.commits[sel].oid, self.data.commits[sel].window_start)) |route| 530 self.session.data.current_page = route; 531 } 532 } 533 } 534 535 // the selected list row shows a border (the focused TextBox upgrades it 536 // to a double border itself); the rest stay borderless. 537 const lb = self.listBox(); 538 for (lb.children.keys(), lb.children.values()) |id, *child| { 539 switch (child.widget) { 540 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 541 else => {}, 542 } 543 } 544 545 // the selected hunk (or the "load more" row) shows a single border (the 546 // focused TextBox upgrades it to a double border itself, so it stays 547 // single when focus is on the commit list); the rest keep their 548 // space-reserving hidden border. 549 const inner = self.diffInner(); 550 for (inner.children.keys(), inner.children.values()) |id, *child| { 551 switch (child.widget) { 552 .text_box => |*tb| tb.options.border_style = if (inner.getFocus().child_id == id) .single else .hidden, 553 else => {}, 554 } 555 } 556 557 // cap the list at list_max_width only while the diff pane fits beside it. 558 // the box drops the diff when the width can't hold both minimums, so when 559 // it's that narrow we lift the cap and let the list fill the whole width. 560 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + diff_min_width else true; 561 self.contentBox().children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 562 563 // stretch the diff pane across the rest of the width so it fills the area 564 // rather than shrinking to its content; its scroll fills the pane. when 565 // too narrow for both, it fills the whole width. 566 if (constraint.max_size.width) |w| { 567 self.contentBox().children.values()[diff_index].min_size = .{ .width = if (both_panes_fit) w - list_max_width else w, .height = null }; 568 } else { 569 self.contentBox().children.values()[diff_index].min_size = .{ .width = diff_min_width, .height = null }; 570 } 571 572 // the web bounds the layout to the browser viewport like the terminal; 573 // each Scroll's web-native mode hands its full content to a real 574 // scrollable element, so we no longer build unbounded here. 575 // 576 // crossing panes only re-selects the content box's child (focusDiff / 577 // focusList); when the window is too narrow to show both, the pane that 578 // held focus is dropped here. the framework recovers focus after the 579 // top-level build by re-deriving it down the selected-child chain, so 580 // there's nothing to fix up afterward. 581 try self.box.build(allocator, constraint, root_focus); 582 } 583 584 fn refreshDiff(self: *View, allocator: std.mem.Allocator) !void { 585 const sel = self.selectedCommitIndex() orelse return; 586 if (self.diffed_index) |d| if (d == sel) return; 587 try self.populateDiff(allocator, sel); 588 self.diffed_index = sel; 589 } 590 591 fn populateDiff(self: *View, allocator: std.mem.Allocator, sel: usize) !void { 592 const commit = self.data.commits[sel]; 593 const inner = self.diffInner(); 594 595 for (inner.children.values()) |*child| child.widget.deinit(allocator); 596 inner.children.clearAndFree(allocator); 597 inner.getFocus().child_id = null; 598 599 // the first row always links to viewing the repo's files at this commit. 600 try self.addViewFilesLink(allocator, inner, commit.oid); 601 602 // a "previous" row and a "next" row at the bottom reload the page on the 603 // adjacent diff window. 604 if (commit.has_prev) try self.addNavLink(allocator, inner, "← previous", commit.oid, commit.window_start -| diff_page); 605 for (commit.hunks) |hunk| { 606 if (hunk.path) |path| try self.addPathBox(allocator, inner, path); 607 try self.addHunkBox(allocator, inner, hunk.lines); 608 } 609 if (commit.has_more) try self.addNavLink(allocator, inner, "next →", commit.oid, commit.window_start + diff_page); 610 611 // point the pane at its first row so focus recovery can land here. 612 if (inner.children.count() > 0) inner.getFocus().child_id = inner.children.keys()[0]; 613 614 // reset the scroll to the top for the newly-shown commit: directly on the 615 // terminal (the wasm offset), and via a version bump on the web (so the 616 // renderer's scroll id changes and JS drops the preserved position). 617 const sc = self.diffScroll(); 618 sc.x = 0; 619 sc.y = 0; 620 sc.getFocus().version +%= 1; 621 } 622 623 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 624 _ = allocator; 625 if (self.diffActive()) { 626 try self.diffInput(key, root_focus); 627 } else { 628 try self.listInput(key, root_focus); 629 } 630 } 631 632 fn listInput(self: *View, key: Key, root_focus: *Focus) !void { 633 // up/down (and the scroll wheel) move the selection a row; page up/down 634 // jump a fixed amount. right/Enter cross into the diff pane. Enter/clicks 635 // on the "next" row become navigation in the host before reaching here. 636 if (inp.rowDelta(key, @intCast(self.listBox().children.count()))) |delta| { 637 ui.moveRowFocus(self.listBox(), self.listScroll(), root_focus, delta); 638 return; 639 } 640 switch (key) { 641 .enter => if (self.selectedCommitIndex() != null) 642 try self.focusDiff(root_focus) 643 else if (self.data.next_start) |next| { 644 if (ui.RoutablePage.repoCommitsRoute(self.data.identity, .object, next, 0)) |route| 645 try self.session.navigate(route); 646 }, 647 .arrow_right => try self.focusDiff(root_focus), 648 else => {}, 649 } 650 } 651 652 fn diffInput(self: *View, key: Key, root_focus: *Focus) !void { 653 const sc = self.diffScroll(); 654 switch (key) { 655 // left scrolls horizontally, then leaves for the list once flush left. 656 .arrow_left => { 657 if (sc.x > 0) { 658 sc.x -= 1; 659 self.diffScroll().clampToContent(); 660 } else try self.focusList(root_focus); 661 }, 662 .arrow_right => { 663 sc.x += 1; 664 self.diffScroll().clampToContent(); 665 }, 666 .arrow_up => try self.moveDiff(root_focus, -1), 667 .arrow_down => try self.moveDiff(root_focus, 1), 668 .page_up => try self.pageDiff(root_focus, -10), 669 .page_down => try self.pageDiff(root_focus, 10), 670 .home => try self.jumpDiff(root_focus, false), 671 .end => try self.jumpDiff(root_focus, true), 672 // Enter / a click on a "previous"/"next" row follow its "a:" link in 673 // the host (it reloads the adjacent window), so they don't reach here. 674 .mouse => |mouse| switch (mouse.action) { 675 .scroll => |dir| try self.moveDiff(root_focus, if (dir == .up) -1 else 1), 676 else => {}, 677 }, 678 else => {}, 679 } 680 } 681 682 // move one step in `delta` (+ down, - up). in the terminal, `delta` is a 683 // line count unless there is a new hunk visible (in which case it is a 684 // hunk count). on the web `delta` is always a hunk count. 685 fn moveDiff(self: *View, root_focus: *Focus, delta: isize) !void { 686 const inner = self.diffInner(); 687 const keys = inner.children.keys(); 688 if (keys.len == 0) return; 689 const cur: usize = if (root_focus.grandchild_id) |g| (inner.children.getIndex(g) orelse 0) else 0; 690 const target = @as(isize, @intCast(cur)) + delta; 691 const in_range = target >= 0 and target < @as(isize, @intCast(keys.len)); 692 693 if (self.session.is_terminal) { 694 if (in_range and self.hunkVisible(@intCast(target))) { 695 root_focus.setFocus(keys[@intCast(target)]); 696 return; 697 } 698 699 const sc = self.diffScroll(); 700 sc.y += delta * 5; // magnify because it's a line count 701 self.diffScroll().clampToContent(); 702 if (in_range and self.hunkVisible(@intCast(target))) { 703 root_focus.setFocus(keys[@intCast(target)]); 704 } 705 } else { 706 if (in_range) { 707 root_focus.setFocus(keys[@intCast(target)]); 708 } 709 } 710 } 711 712 // page a fixed number of lines, then focus the leading visible hunk 713 // (bottom-most when paging down, top-most when paging up). in the 714 // terminal, `delta` is a line count, and on the web it's a hunk count. 715 fn pageDiff(self: *View, root_focus: *Focus, delta: isize) !void { 716 if (self.session.is_terminal) { 717 const sc = self.diffScroll(); 718 sc.y += delta * 5; // magnify because it's a line count 719 self.diffScroll().clampToContent(); 720 try self.focusVisible(root_focus, delta > 0); 721 } else { 722 const inner = self.diffInner(); 723 const keys = inner.children.keys(); 724 if (keys.len == 0) return; 725 const cur: isize = if (root_focus.grandchild_id) |g| @intCast(inner.children.getIndex(g) orelse 0) else 0; 726 const target: usize = @intCast(std.math.clamp(cur + delta, 0, @as(isize, @intCast(keys.len - 1)))); 727 root_focus.setFocus(keys[target]); 728 } 729 } 730 731 // jump to the first or last hunk. on the web the browser scrolls to the 732 // focused hunk; on the terminal pin the scroll to the top/bottom too. 733 fn jumpDiff(self: *View, root_focus: *Focus, to_end: bool) !void { 734 const inner = self.diffInner(); 735 const keys = inner.children.keys(); 736 if (keys.len == 0) return; 737 if (self.session.is_terminal) { 738 const sc = self.diffScroll(); 739 sc.y = if (to_end) std.math.maxInt(isize) else 0; 740 self.diffScroll().clampToContent(); 741 } 742 root_focus.setFocus(if (to_end) keys[keys.len - 1] else keys[0]); 743 } 744 745 // whether hunk `index` is at least partly within the diff viewport, per the 746 // last build's layout rects (content space) and the current scroll offset. 747 fn hunkVisible(self: *View, index: usize) bool { 748 const inner = self.diffInner(); 749 const sc = self.diffScroll(); 750 const vp = sc.grid orelse return false; 751 const r = inner.children.values()[index].rect orelse return false; 752 const top = sc.y; 753 const bottom = sc.y + @as(isize, @intCast(vp.size.height)); 754 return (r.y + @as(isize, @intCast(r.size.height))) > top and r.y < bottom; 755 } 756 757 // focus the visible hunk at the scroll's leading edge. `prefer_last` picks 758 // the bottom-most visible (for downward motion), else the top-most. 759 fn focusVisible(self: *View, root_focus: *Focus, prefer_last: bool) !void { 760 const inner = self.diffInner(); 761 const sc = self.diffScroll(); 762 const vp = sc.grid orelse return; 763 const top = sc.y; 764 const bottom = sc.y + @as(isize, @intCast(vp.size.height)); 765 var chosen: ?usize = null; 766 for (inner.children.keys(), inner.children.values()) |id, *child| { 767 const r = child.rect orelse continue; // content-space layout rect 768 const r_top = r.y; 769 const r_bot = r.y + @as(isize, @intCast(r.size.height)); 770 if (r_bot <= top or r_top >= bottom) continue; // not visible 771 chosen = id; 772 if (!prefer_last) break; // first visible 773 } 774 if (chosen) |id| root_focus.setFocus(id); 775 } 776 777 // enter the diff pane. the host arrives here on right-arrow or Enter from the 778 // list. a diff with no rows can't be entered. setFocus handles the too-narrow 779 // case where the pane isn't laid out yet (it gets selected, then focused after 780 // the next build, landing on its remembered hunk). 781 fn focusDiff(self: *View, root_focus: *Focus) !void { 782 if (self.diffInner().children.count() == 0) return; 783 root_focus.setFocus(self.diffOuter().getFocus().id); 784 } 785 786 // return to the list. 787 fn focusList(self: *View, root_focus: *Focus) !void { 788 root_focus.setFocus(self.listScroll().getFocus().id); 789 } 790 791 pub fn clearGrid(self: *View) void { 792 self.box.clearGrid(); 793 } 794 795 pub fn getGrid(self: View) ?Grid { 796 return self.box.getGrid(); 797 } 798 799 pub fn getFocus(self: *View) *Focus { 800 return self.box.getFocus(); 801 } 802 803 // for the parent's "scroll up at the top jumps to the header" check. in the 804 // diff pane that means the first hunk is focused and the diff can't scroll up 805 // any further; otherwise up-arrow stays in the pane (scrolling or moving 806 // between hunks). when the list holds focus, report its selection directly. 807 pub fn getSelectedIndex(self: *View) ?usize { 808 if (self.diffActive()) { 809 const inner = self.diffInner(); 810 const cid = inner.getFocus().child_id orelse return 1; 811 const first_focused = inner.children.count() > 0 and cid == inner.children.keys()[0]; 812 return if (first_focused and self.diffScroll().y == 0) 0 else 1; 813 } 814 const lb = self.listBox(); 815 const cid = lb.getFocus().child_id orelse return null; 816 return lb.children.getIndex(cid); 817 } 818 }; 819 820 // the "a:" navigation link for the commits page walking from commit `oid` within 821 // `identity`, showing the selected commit's first `after` hunks (0 = default). 822 fn commitsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8, after: usize) ![]const u8 { 823 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, after) orelse return error.RouteTooLong; 824 const url = try route.urlAlloc(page_arena); 825 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 826 } 827 828 // the "a:" link to the files tab at commit `oid` (an object ref), at its root 829 // directory, within `identity` ("owner/name"). 830 fn filesObjectLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 831 const route = ui.RoutablePage.repoFilesRoute(identity, .object, oid, "", 0) orelse return error.RouteTooLong; 832 const url = try route.urlAlloc(page_arena); 833 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 834 } 835 836 // the in-page "ai:" anchor for selecting `oid` in `identity`'s commit list. it 837 // points at the same route as commitsLink but the "ai:" prefix keeps wasm clicks 838 // in-page (crossPageLink ignores it); the href is only followed with js off. 839 fn commitRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 840 const route = ui.RoutablePage.repoCommitsRoute(identity, .object, oid, 0) orelse return error.RouteTooLong; 841 const url = try route.urlAlloc(page_arena); 842 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 843 } 844