From 1aef0f292fd20bbef0a7d284d1ab0060947626e2 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Tue, 18 Nov 2025 07:34:51 -0600 Subject: [PATCH] fix: respect borrow boxes display setting regardless of actual borrowing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, borrow boxes only appeared when borrowing actually occurred in a column, even if the user set the display rule to 'always'. The Typst template was duplicating the 'whenRegrouping' logic that's already handled by the TypeScript evaluateRule() function. Changes: - Remove actual-borrowing check from shows-borrow condition - Add column-needs-borrow variable to track where borrowing occurs - Use column-needs-borrow for hints (only show where actually needed) - Borrow boxes now respect user's 'always'/'never' setting Now: - 'always': boxes show for all columns > 0, hints only where borrowing occurs - 'never': no boxes or hints - 'whenRegrouping': boxes and hints only where borrowing occurs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../worksheets/typstHelpers/subtraction/borrowBoxes.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/create/worksheets/typstHelpers/subtraction/borrowBoxes.ts b/apps/web/src/app/create/worksheets/typstHelpers/subtraction/borrowBoxes.ts index 9796dd20..359df45b 100644 --- a/apps/web/src/app/create/worksheets/typstHelpers/subtraction/borrowBoxes.ts +++ b/apps/web/src/app/create/worksheets/typstHelpers/subtraction/borrowBoxes.ts @@ -36,9 +36,10 @@ export function generateBorrowBoxesRow(cellDimensions: CellDimensions): string { // Borrow boxes row (shows borrows FROM higher place TO lower place) [], // Empty cell for operator column ..for i in range(0, grid-digits).rev() { - // Check if we need to borrow FROM this place (to give to i-1) - // We borrow when m-digit < s-digit at position i-1 - let shows-borrow = show-borrows and i > 0 and (m-digits.at(i - 1) < s-digits.at(i - 1)) + // Show borrow box if enabled (display rules already handle "whenRegrouping" logic in TypeScript) + // Note: Borrowing occurs FROM position i TO position i-1 (when m-digits.at(i-1) < s-digits.at(i-1)) + let shows-borrow = show-borrows and i > 0 + let column-needs-borrow = i > 0 and (m-digits.at(i - 1) < s-digits.at(i - 1)) if shows-borrow { // This place borrowed FROM to give to lower place @@ -46,7 +47,8 @@ export function generateBorrowBoxesRow(cellDimensions: CellDimensions): string { let dest-color = place-colors.at(i - 1) // Lower place (receiving) // When showing hints, determine what to display based on cascading - if show-borrowing-hints and i <= m-highest { + // Only show hints where borrowing actually occurs (even if boxes show everywhere) + if show-borrowing-hints and column-needs-borrow and i <= m-highest { // Determine the actual value to show in the hint // For cascading: if this digit is 0, it received 10 from left and gives 1 to right // So it shows "10 - 1". Otherwise it shows "original - 1"