From dc25f243a4f5d0fc9971d52fca91c7876e78225d Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Mon, 13 Apr 2026 11:58:32 +0200 Subject: [PATCH] Fix colspan: use original words before split_cross_column_words _split_cross_column_words was destroying the colspan information by cutting word-blocks at column boundaries BEFORE _detect_colspan_cells could analyze them. Now passes original (pre-split) words to colspan detection while using split words for cell building. Co-Authored-By: Claude Opus 4.6 (1M context) --- klausur-service/backend/grid_editor_helpers.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/klausur-service/backend/grid_editor_helpers.py b/klausur-service/backend/grid_editor_helpers.py index 90c55b9..a1831c3 100644 --- a/klausur-service/backend/grid_editor_helpers.py +++ b/klausur-service/backend/grid_editor_helpers.py @@ -1424,6 +1424,8 @@ def _build_zone_grid( # Split word boxes that straddle column boundaries (e.g. "sichzie" # spanning Col 1 + Col 2). Must happen after column detection and # before cell assignment. + # Keep original words for colspan detection (split destroys span info). + original_zone_words = zone_words if len(columns) >= 2: zone_words = _split_cross_column_words(zone_words, columns) @@ -1431,11 +1433,11 @@ def _build_zone_grid( cells = _build_cells(zone_words, columns, rows, img_w, img_h) # --- Detect colspan (merged cells spanning multiple columns) --- - # A word-block that extends across column boundaries indicates a merged - # cell (like Excel cell-merge). Detect these and replace the split - # cells with a single spanning cell. + # Uses the ORIGINAL (pre-split) words to detect word-blocks that span + # multiple columns. _split_cross_column_words would have destroyed + # this information by cutting words at column boundaries. if len(columns) >= 2: - cells = _detect_colspan_cells(zone_words, columns, rows, cells, img_w, img_h) + cells = _detect_colspan_cells(original_zone_words, columns, rows, cells, img_w, img_h) # Prefix cell IDs with zone index for cell in cells: