╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Refs.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
395 } 396 397 // land on the other column's row at or above the current one: its first 398 // name when moving right, its last when moving left. names are laid out in 399 // order, so that row ends at the last name no lower than the current one. 400 fn crossTo(self: *View, target: usize, from_y: isize, root_focus: *Focus) void { 401 // the other column may have no names at all 402 const rects = self.flowAt(target).rects.items; 403 if (rects.len == 0) return; 404 var last: usize = 0; 405 for (rects, 0..) |rect, i| { 406 if (rect.y <= from_y) last = i; 407 } 408 var first = last; 409 while (first > 0 and rects[first - 1].y == rects[last].y) first -= 1; 410 self.focusName(target, if (target == right_col) first else last, root_focus); 411 } 412 413 fn focusName(self: *View, index: usize, item: usize, root_focus: *Focus) void { 414 const flow = self.flowAt(index); 415 root_focus.setFocus(flow.text_boxes.items[item].getFocus().id); 416 // the browser scrolls natively; the terminal brings the name into view 417 if (self.session.is_terminal and item < flow.rects.items.len) self.scrollAt(index).scrollToRect(flow.rects.items[item]); 418 } 419 420 pub fn clearGrid(self: *View) void { 421 self.box.clearGrid(); 422 } 423 424 pub fn getGrid(self: View) ?Grid { 425 return self.box.getGrid(); 426 } 427 428 pub fn getFocus(self: *View) *Focus { 429 return self.box.getFocus(); 430 } 431 432 // up leaves the tab from the search box 433 pub fn atTop(self: *View) bool { 434 return self.headerActive(); 435 } 436 437 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 438 root_focus.setFocus(self.searchBox().getFocus().id); 439 return true; 440 } 441 }; 442 443 // the "a:" link to `kind`'s column windowed from ref `name` (raw; "" = the 444 // first window) within `identity` ("owner:name"). the other column resets to 445 // its first window. 446 fn windowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, kind: ui.RoutablePage.RefKind, name: []const u8, search: []const u8) ![]const u8 { 447 const encoded = try ui.urlEncodeRef(page_arena.allocator(), name); 448 const window = ui.RoutablePage.repoRefsRoute(identity, kind, encoded) orelse return error.RouteTooLong; 449 const route = window.withSearch(search) orelse return error.RouteTooLong; 450 const url = try route.toUrl(page_arena); 451 return page_arena.allocator().print("a:{s}", .{url}); 452 } 453 454 // the "a:" link to the files tab at ref `name` (a branch or tag) within 455 // `identity` ("owner:name"), at its root directory. the name is percent-encoded 456 // since it can contain a '/'. 457 fn refLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, kind: ui.RoutablePage.RefKind, name: []const u8) ![]const u8 { 458 const aa = page_arena.allocator(); 459 const ref_or_oid: ui.RoutablePage.RefOrOid = switch (kind) { 460 .branch => .branch, 461 .tag => .tag, 462 }; 463 const value = try ui.urlEncodeRef(aa, name); 464 const route = ui.RoutablePage.repoFilesRoute(identity, ref_or_oid, value, "", 0) orelse return error.RouteTooLong; 465 const url = try route.toUrl(page_arena); 466 return aa.print("a:{s}", .{url}); 467 } 468