╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Comments.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
471 472 fn moveVertical(self: *View, root_focus: *Focus, down: bool) bool { 473 const box = self.content(); 474 const current = self.focusedChild(root_focus) orelse return false; 475 if (box.children.values()[current].widget == .repo_comment) { 476 const comment = &box.children.values()[current].widget.repo_comment; 477 if (down and !comment.bodyFocused()) { 478 self.focusChild(current, true, root_focus); 479 return true; 480 } 481 if (!down and comment.bodyFocused()) { 482 self.focusChild(current, false, root_focus); 483 return true; 484 } 485 } 486 487 var next = current; 488 while (true) { 489 if (down) { 490 next += 1; 491 if (next >= box.children.count()) return false; 492 } else { 493 if (next == 0) return false; 494 next -= 1; 495 } 496 if (!self.childFocusable(next)) continue; 497 self.focusChild(next, !down, root_focus); 498 return true; 499 } 500 } 501 502 fn moveHorizontal(self: *View, root_focus: *Focus, right: bool) bool { 503 const box = self.content(); 504 const current = self.focusedChild(root_focus) orelse return false; 505 const child = &box.children.values()[current]; 506 if (child.widget == .repo_comment) { 507 const moved = child.widget.repo_comment.moveHorizontal(root_focus, right); 508 if (moved) if (child.rect) |rect| self.scroll.scrollToRect(rect); 509 return moved; 510 } 511 const row = switch (child.widget) { 512 .box => |*row| row, 513 else => return false, 514 }; 515 const selected = row.getFocus().child_id orelse return false; 516 const selected_index = row.children.getIndex(selected) orelse return false; 517 const target = if (right) selected_index + 1 else selected_index -| 1; 518 if (target == selected_index or target >= row.children.count()) return false; 519 root_focus.setFocus(row.children.keys()[target]); 520 if (child.rect) |rect| self.scroll.scrollToRect(rect); 521 return true; 522 } 523 524 pub fn clearGrid(self: *View) void { 525 self.scroll.clearGrid(); 526 } 527 528 pub fn getGrid(self: View) ?Grid { 529 return self.scroll.getGrid(); 530 } 531 532 pub fn getFocus(self: *View) *Focus { 533 return self.scroll.getFocus(); 534 } 535 536 pub fn getSelectedIndex(self: *View) ?usize { 537 const box = self.content(); 538 const selected = box.getFocus().child_id orelse return null; 539 for (box.children.keys(), 0..) |id, index| { 540 if (!self.childFocusable(index)) continue; 541 if (id != selected) return 1; 542 return switch (box.children.values()[index].widget) { 543 .repo_comment => |*comment| if (comment.bodyFocused()) 1 else 0, 544 else => 0, 545 }; 546 } 547 return null; 548 } 549 }; 550