╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Refs.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
307 308 fn activeColumn(self: *View) ?*wgt.Box(ui.Widget) { 309 return &(self.activeScroll() orelse return null).child.box; 310 } 311 312 fn switchColumn(self: *View, root_focus: *Focus, target: usize) !void { 313 if (target >= self.box.children.count()) return; 314 const cur_col = self.activeColumn() orelse return; 315 const target_scroll = columnScroll(&self.box.children.values()[target].widget.box); 316 const target_col = &target_scroll.child.box; 317 // an empty column has nothing to select; ignore. 318 if (target_col.children.count() == 0) return; 319 // keep the same row offset, clamped to the target column's last row. 320 const cur_id = cur_col.getFocus().child_id orelse return; 321 const cur = cur_col.children.getIndex(cur_id) orelse return; 322 const last = target_col.children.count() - 1; 323 const next = @min(cur, last); 324 root_focus.setFocus(target_col.children.keys()[next]); 325 if (target_col.children.values()[next].rect) |rect| target_scroll.scrollToRect(rect); 326 } 327 328 pub fn clearGrid(self: *View) void { 329 self.box.clearGrid(); 330 } 331 332 pub fn getGrid(self: View) ?Grid { 333 return self.box.getGrid(); 334 } 335 336 pub fn getFocus(self: *View) *Focus { 337 return self.box.getFocus(); 338 } 339 340 // the selected row's offset within the active column (0 = first row), so the 341 // parent knows when up should escape to the header. 342 pub fn getSelectedIndex(self: View) ?usize { 343 var copy = self; 344 const col = copy.activeColumn() orelse return null; 345 const cur_id = col.getFocus().child_id orelse return null; 346 return col.children.getIndex(cur_id); 347 } 348 }; 349 350 // the "a:" link to `kind`'s column windowed from ref `name` (raw; "" = the 351 // first window) within `identity` ("owner/name"). the other column resets to 352 // its first window. 353 fn windowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, kind: ui.RoutablePage.RefKind, name: []const u8) ![]const u8 { 354 const encoded = try ui.urlEncodeRef(page_arena.allocator(), name); 355 const route = ui.RoutablePage.repoRefsRoute(identity, kind, encoded) orelse return error.RouteTooLong; 356 const url = try route.toUrl(page_arena); 357 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 358 } 359 360 // the "a:" link to the files tab at ref `name` (a branch or tag) within 361 // `identity` ("owner/name"), at its root directory. the name is percent-encoded 362 // since it can contain a '/'. 363 fn refLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, kind: ui.RoutablePage.RefKind, name: []const u8) ![]const u8 { 364 const aa = page_arena.allocator(); 365 const ref_or_oid: ui.RoutablePage.RefOrOid = switch (kind) { 366 .branch => .branch, 367 .tag => .tag, 368 }; 369 const value = try ui.urlEncodeRef(aa, name); 370 const route = ui.RoutablePage.repoFilesRoute(identity, ref_or_oid, value, "", 0) orelse return error.RouteTooLong; 371 const url = try route.toUrl(page_arena); 372 return std.fmt.allocPrint(aa, "a:{s}", .{url}); 373 } 374