╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Diff.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
258 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 259 errdefer box.deinit(allocator); 260 break :blk .{ .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = box }, .{ .direction = .both, .web_native = !session.is_terminal, .fill = true }) }; 261 }; 262 errdefer view.deinit(allocator); 263 const box = view.inner(); 264 try data.appendWindow(allocator, session, box); 265 if (box.children.count() == 0) try addLink(allocator, box, "no changes", ""); 266 box.getFocus().child_id = box.children.keys()[0]; 267 return view; 268 } 269 270 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 271 self.scroll.deinit(allocator); 272 } 273 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 274 self.clearGrid(); 275 try self.scroll.build(allocator, constraint, root_focus); 276 } 277 pub fn clearGrid(self: *View) void { 278 self.scroll.clearGrid(); 279 } 280 pub fn getGrid(self: View) ?Grid { 281 return self.scroll.getGrid(); 282 } 283 pub fn getFocus(self: *View) *Focus { 284 return self.scroll.getFocus(); 285 } 286 pub fn atTop(self: *View) bool { 287 const box = self.inner(); 288 return self.scroll.y == 0 and (box.children.count() == 0 or box.getFocus().child_id == box.children.keys()[0]); 289 } 290 fn inner(self: *View) *wgt.Box(ui.Widget) { 291 return &self.scroll.child.box; 292 } 293 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 294 _ = allocator; 295 const sc = &self.scroll; 296 const box = self.inner(); 297 if (inp.rowDelta(key, @intCast(box.children.count()))) |delta| return ui.widget.moveRowFocus(box, sc, root_focus, delta); 298 switch (key) { 299 // scroll horizontally within the diff 300 .arrow_left => if (!ui.widget.moveInSelectedRow(box, root_focus, false) and sc.x > 0) { 301 sc.x -= 1; 302 sc.clampToContent(); 303 }, 304 .arrow_right => if (!ui.widget.moveInSelectedRow(box, root_focus, true)) { 305 sc.x += 1; 306 sc.clampToContent(); 307 }, 308 // Enter / a click on a "previous"/"next" row follow its "a:" link in 309 // the host (it reloads the adjacent window), so they don't reach here. 310 else => {}, 311 } 312 } 313 }; 314