a73x

124ae700

refactor: drop the Grid.clipCol and Grid.snapWide wrappers

a73x   2026-09-04 18:04

Commit message
refactor: drop the Grid.clipCol and Grid.snapWide wrappers

Both were pub methods on the production Grid whose only callers were grid.zig's
own tests; paint.zig reaches for the free functions `clipColOf`/`snapWideOf`.
The tests call those directly now, so the two spellings are one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CsWfuJFQbTfGtKZLS5qw4q

src/engine/grid.zig
Old New
@@ -241,13 +241,6 @@ pub const Grid = struct {
241 return dumpRowsPlain(alloc, self.lines); 241 return dumpRowsPlain(alloc, self.lines);
242 } 242 }
243 243
244 pub fn clipCol(self: *const Grid, y: u16, view: RowView) ?u16 {
245 return clipColOf(&self.lines[y], self.cols, view);
246 }
247
248 pub fn snapWide(self: *const Grid, y: u16, from: u16, to: u16) ColSpan {
249 return snapWideOf(&self.lines[y], self.cols, from, to);
250 }
251 }; 244 };
252 245
253 test "grid: applyRow fills the row and blanks the rest of the width" { 246 test "grid: applyRow fills the row and blanks the rest of the width" {
@@ -306,7 +299,7 @@ test "grid: dumpPlain trims trailing blanks per row, joins rows with newlines, a
306 try std.testing.expectEqualStrings("a b", s); 299 try std.testing.expectEqualStrings("a b", s);
307 } 300 }
308 301
309 test "grid: clipCol steps inward off a wide glyph at the pane edge; snapWide steps outward" { 302 test "grid: clipColOf steps inward off a wide glyph at the pane edge; snapWideOf steps outward" {
310 const alloc = std.testing.allocator; 303 const alloc = std.testing.allocator;
311 const g = try Grid.init(alloc, 6, 2); 304 const g = try Grid.init(alloc, 6, 2);
312 defer g.deinit(); 305 defer g.deinit();
@@ -323,15 +316,15 @@ test "grid: clipCol steps inward off a wide glyph at the pane edge; snapWide ste
323 // The pane starts at screen column 4; every answer below is a GRID column, 316 // The pane starts at screen column 4; every answer below is a GRID column,
324 // so the offset must not reach it. 317 // so the offset must not reach it.
325 // A pane 2 wide would cut 漢 in half: the last column that fits is 0. 318 // A pane 2 wide would cut 漢 in half: the last column that fits is 0.
326 try std.testing.expectEqual(@as(?u16, 0), g.clipCol(1, .{ .col_off = 4, .cols = 2 })); 319 try std.testing.expectEqual(@as(?u16, 0), clipColOf(&g.lines[1], g.cols, .{ .col_off = 4, .cols = 2 }));
327 // A pane as wide as the grid clips at the last COLUMN, not at the last 320 // A pane as wide as the grid clips at the last COLUMN, not at the last
328 // written one: trailing blanks are cells a pane paints like any other. 321 // written one: trailing blanks are cells a pane paints like any other.
329 try std.testing.expectEqual(@as(?u16, 5), g.clipCol(1, .{ .col_off = 4, .cols = 6 })); 322 try std.testing.expectEqual(@as(?u16, 5), clipColOf(&g.lines[1], g.cols, .{ .col_off = 4, .cols = 6 }));
330 try std.testing.expectEqual(@as(?u16, null), g.clipCol(1, .{ .col_off = 4, .cols = 0 })); 323 try std.testing.expectEqual(@as(?u16, null), clipColOf(&g.lines[1], g.cols, .{ .col_off = 4, .cols = 0 }));
331 // The unwritten row 0 has no wide glyph, so nothing steps inward there. 324 // The unwritten row 0 has no wide glyph, so nothing steps inward there.
332 try std.testing.expectEqual(@as(?u16, 1), g.clipCol(0, .{ .col_off = 4, .cols = 2 })); 325 try std.testing.expectEqual(@as(?u16, 1), clipColOf(&g.lines[0], g.cols, .{ .col_off = 4, .cols = 2 }));
333 // A drag from the spacer to the wide cell covers the whole glyph. 326 // A drag from the spacer to the wide cell covers the whole glyph.
334 const s = g.snapWide(1, 2, 1); 327 const s = snapWideOf(&g.lines[1], g.cols, 2, 1);
335 try std.testing.expectEqual(@as(u16, 1), s.from); 328 try std.testing.expectEqual(@as(u16, 1), s.from);
336 try std.testing.expectEqual(@as(u16, 2), s.to); 329 try std.testing.expectEqual(@as(u16, 2), s.to);
337 } 330 }