╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
439 const direction = inp.vertDirection(key); 440 if (self.headerActive()) { 441 const search_box = self.searchBox(); 442 if (direction == .down) return root_focus.setFocus(self.listScroll().getFocus().id); 443 if (key == .enter) { 444 const text = try search_box.text(allocator); 445 defer allocator.free(text); 446 return self.submit(text); 447 } 448 return search_box.input(allocator, key, root_focus); 449 } 450 // up from the first row reaches the search box 451 if (direction == .up and self.listScroll().atTop()) return self.focusHeader(root_focus); 452 try self.listScroll().input(allocator, key, root_focus); 453 } 454 455 // the repos narrowed to `text` from the first window. an empty box on an 456 // unsearched page has nothing to clear. 457 fn submit(self: *ReposView, text: []const u8) !void { 458 if (text.len == 0 and self.data.repos_search == null) return; 459 const route = reposRoute(self.data.user.name) orelse return; 460 try self.session.navigate(route.withSearch(text) orelse return); 461 } 462 463 fn searchBox(self: *ReposView) *ui.widget.SearchBox { 464 return &self.box.children.values()[header_index].widget.box.children.values()[0].widget.search_box; 465 } 466 467 fn listScroll(self: *ReposView) *ui.widget.FlowBox.Scroll { 468 return &self.box.children.values()[list_index].widget.flow_box_scroll; 469 } 470 471 fn headerActive(self: *ReposView) bool { 472 return self.box.getFocus().child_id == self.box.children.keys()[header_index]; 473 } 474 475 pub fn clearGrid(self: *ReposView) void { 476 self.box.clearGrid(); 477 } 478 479 pub fn getGrid(self: ReposView) ?Grid { 480 return self.box.getGrid(); 481 } 482 483 pub fn getFocus(self: *ReposView) *Focus { 484 return self.box.getFocus(); 485 } 486 487 // up leaves the tab from the search box 488 pub fn atTop(self: *ReposView) bool { 489 return self.headerActive(); 490 } 491 492 pub fn focusHeader(self: *ReposView, root_focus: *Focus) void { 493 root_focus.setFocus(self.searchBox().getFocus().id); 494 } 495 }; 496 497 // the first window of `name`'s repos 498 fn reposRoute(name: []const u8) ?ui.RoutablePage { 499 return .{ .user_repos = .{ .name = ui.RoutablePage.Array(evt.User.name_max_len).from(name) orelse return null } }; 500 } 501