From 338bcd7d162f36488fd1b53f9cb0ce9865096322 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 7 Jan 2024 19:08:24 -0300 Subject: [PATCH] improve 'grid-get-row' (backport) Backport e32d71efdbae28e0ca2ff527ffd1c808cb7dcc93 --- tablex.typ | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tablex.typ b/tablex.typ index 1baff6b..eadea93 100644 --- a/tablex.typ +++ b/tablex.typ @@ -697,7 +697,24 @@ // Fetches an entire row of cells (all positions with the given y). #let grid-get-row(grid, y) = { - range(grid.width).map(x => grid-at(grid, x, y)) + let len = grid.items.len() + // position of the first cell in that row. + let first-row-pos = grid-index-at(0, y, grid: grid) + if len <= first-row-pos { + // grid isn't large enough, so no row to return + (none,) * grid.width + } else { + // position right after the last cell in this row + let next-row-pos = first-row-pos + grid.width + let cell-row = grid.items.slice(first-row-pos, calc.min(len, next-row-pos)) + let cell-row-len = cell-row.len() + if cell-row-len < grid.width { + // the row isn't complete because the grid wasn't large enough. + let missing-cells = (none,) * (grid.width - cell-row-len) + cell-row += missing-cells + } + cell-row + } } // Fetches an entire column of cells (all positions with the given x).