╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Diff.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
393 if (self.session.is_terminal) { 394 const sc = &self.scroll; 395 sc.y = if (to_end) std.math.maxInt(isize) else 0; 396 self.scroll.clampToContent(); 397 } 398 root_focus.setFocus(if (to_end) keys[keys.len - 1] else keys[0]); 399 } 400 401 // whether hunk `index` is at least partly within the diff viewport, per the 402 // last build's layout rects (content space) and the current scroll offset. 403 fn hunkVisible(self: *View, index: usize) bool { 404 const box = self.inner(); 405 const sc = &self.scroll; 406 const vp = sc.grid orelse return false; 407 const r = box.children.values()[index].rect orelse return false; 408 const top = sc.y; 409 const bottom = sc.y + @as(isize, @intCast(vp.size.height - sc.bar_h)); 410 return (r.y + @as(isize, @intCast(r.size.height))) > top and r.y < bottom; 411 } 412 413 // focus the visible hunk at the scroll's leading edge. `prefer_last` picks 414 // the bottom-most visible (for downward motion), else the top-most. 415 fn focusVisible(self: *View, root_focus: *Focus, prefer_last: bool) void { 416 const box = self.inner(); 417 const sc = &self.scroll; 418 const vp = sc.grid orelse return; 419 const top = sc.y; 420 const bottom = sc.y + @as(isize, @intCast(vp.size.height - sc.bar_h)); 421 var chosen: ?usize = null; 422 for (box.children.keys(), box.children.values()) |id, *child| { 423 const r = child.rect orelse continue; // content-space layout rect 424 const r_top = r.y; 425 const r_bot = r.y + @as(isize, @intCast(r.size.height)); 426 if (r_bot <= top or r_top >= bottom) continue; // not visible 427 chosen = id; 428 if (!prefer_last) break; // first visible 429 } 430 if (chosen) |id| root_focus.setFocus(id); 431 } 432 }; 433