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: