╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Refs.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
348 .end => self.focusName(index, count - 1, root_focus), 349 else => {}, 350 } 351 } 352 353 // both lists narrowed to `text`, each from its first window. an empty box 354 // on an unsearched page has nothing to clear. 355 fn submit(self: *View, text: []const u8) !void { 356 if (text.len == 0 and self.data.search == null) return; 357 const route = ui.RoutablePage.repoRefsRoute(self.data.identity, .branch, "") orelse return; 358 try self.session.navigate(route.withSearch(text) orelse return); 359 } 360 361 fn searchBox(self: *View) *ui.widget.SearchBox { 362 return &self.box.children.values()[header_index].widget.header_scroll.row().children.values()[0].widget.search_box; 363 } 364 365 fn headerActive(self: *View) bool { 366 return self.box.getFocus().child_id == self.box.children.keys()[header_index]; 367 } 368 369 fn columns(self: *View) *wgt.Box(ui.Widget) { 370 return &self.box.children.values()[columns_index].widget.box; 371 } 372 373 fn activeIndex(self: *View) ?usize { 374 const cols = self.columns(); 375 const id = cols.getFocus().child_id orelse return null; 376 return cols.children.getIndex(id); 377 } 378 379 // [0] = the fixed label, [1] = the scrolling flow 380 fn scrollAt(self: *View, index: usize) *wgt.Scroll(ui.Widget) { 381 return &self.columns().children.values()[index].widget.box.children.values()[1].widget.scroll; 382 } 383 384 fn flowAt(self: *View, index: usize) *ui.widget.WordFlow { 385 return &self.scrollAt(index).child.word_flow; 386 } 387 388 fn rowStart(flow: *ui.widget.WordFlow, item: usize) bool { 389 const rects = flow.rects.items; 390 return item == 0 or rects[item - 1].y != rects[item].y; 391 } 392 393 fn rowEnd(flow: *ui.widget.WordFlow, item: usize) bool { 394 const rects = flow.rects.items; 395 return item + 1 == rects.len or rects[item + 1].y != rects[item].y; 396 } 397 398 // land on the other column's row at or above the current one: its first 399 // name when moving right, its last when moving left. names are laid out in 400 // order, so that row ends at the last name no lower than the current one. 401 fn crossTo(self: *View, target: usize, from_y: isize, root_focus: *Focus) void { 402 // the other column may have no names at all 403 const rects = self.flowAt(target).rects.items; 404 if (rects.len == 0) return; 405 var last: usize = 0; 406 for (rects, 0..) |rect, i| { 407 if (rect.y <= from_y) last = i; 408 } 409 var first = last; 410 while (first > 0 and rects[first - 1].y == rects[last].y) first -= 1; 411 self.focusName(target, if (target == right_col) first else last, root_focus); 412 } 413 414 fn focusName(self: *View, index: usize, item: usize, root_focus: *Focus) void { 415 const flow = self.flowAt(index); 416 root_focus.setFocus(flow.text_boxes.items[item].getFocus().id); 417 // the browser scrolls natively; the terminal brings the name into view 418 if (self.session.is_terminal and item < flow.rects.items.len) self.scrollAt(index).scrollToRect(flow.rects.items[item]); 419 } 420 421 pub fn clearGrid(self: *View) void { 422 self.box.clearGrid(); 423 } 424 425 pub fn getGrid(self: View) ?Grid { 426 return self.box.getGrid(); 427 } 428 429 pub fn getFocus(self: *View) *Focus { 430 return self.box.getFocus(); 431 } 432 433 // up leaves the tab from the search box 434 pub fn atTop(self: *View) bool { 435 return self.headerActive(); 436 } 437 438 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 439 root_focus.setFocus(self.searchBox().getFocus().id); 440 return true; 441 } 442 }; 443 444 // the "a:" link to `kind`'s column windowed from ref `name` (raw; "" = the 445 // first window) within `identity` ("owner:name"). the other column resets to 446 // its first window. 447 fn windowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, kind: ui.RoutablePage.RefKind, name: []const u8, search: []const u8) ![]const u8 { 448 const encoded = try ui.urlEncodeRef(page_arena.allocator(), name); 449 const window = ui.RoutablePage.repoRefsRoute(identity, kind, encoded) orelse return error.RouteTooLong; 450 const route = window.withSearch(search) orelse return error.RouteTooLong; 451 const url = try route.toUrl(page_arena); 452 return page_arena.allocator().print("a:{s}", .{url}); 453 } 454 455 // the "a:" link to the files tab at ref `name` (a branch or tag) within 456 // `identity` ("owner:name"), at its root directory. the name is percent-encoded 457 // since it can contain a '/'. 458 fn refLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, kind: ui.RoutablePage.RefKind, name: []const u8) ![]const u8 { 459 const aa = page_arena.allocator(); 460 const ref_or_oid: ui.RoutablePage.RefOrOid = switch (kind) { 461 .branch => .branch, 462 .tag => .tag, 463 }; 464 const value = try ui.urlEncodeRef(aa, name); 465 const route = ui.RoutablePage.repoFilesRoute(identity, ref_or_oid, value, "", 0) orelse return error.RouteTooLong; 466 const url = try route.toUrl(page_arena); 467 return aa.print("a:{s}", .{url}); 468 } 469