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