diff --git a/components/timeshift-spreadsheet.tsx b/components/timeshift-spreadsheet.tsx index e5fb797..813940c 100644 --- a/components/timeshift-spreadsheet.tsx +++ b/components/timeshift-spreadsheet.tsx @@ -411,28 +411,76 @@ export function TimeshiftSpreadsheet({ teamId, teamName }: TimeshiftSpreadsheetP const rows = table.querySelectorAll('tr') if (rows[0]) { const cells = rows[0].querySelectorAll('td') - const targetCell = cells[x + 1] as HTMLElement // +1 because first cell is row number - console.log("Target cell found:", !!targetCell, "Target cell:", targetCell) + let targetCell = cells[x + 1] as HTMLElement // +1 because first cell is row number + console.log("Initial target cell found:", !!targetCell, "Cell display:", targetCell?.style.display, "Target cell:", targetCell) + + // Handle both hidden and visible cells + if (targetCell) { + if (targetCell.style.display === 'none') { + console.log("🔍 Target cell is hidden, finding visible merged cell...") + const targetX = parseInt(String(x)) + + // For merged cells, find the visible cell that represents this position + let foundCell = null + + // Look for visible cells around this position + for (let i = 1; i < cells.length; i++) { + const cell = cells[i] as HTMLElement + if (cell && cell.style.display !== 'none') { + const cellX = parseInt(cell.getAttribute('data-x') || '0') + const cellSpan = cell.colSpan || 1 + + // Check if this visible cell covers our target position + if (cellX <= targetX && targetX < cellX + cellSpan) { + foundCell = cell + console.log("🎯 Found covering visible cell:", foundCell, "covers position", targetX) + break + } + } + } + + if (foundCell) { + targetCell = foundCell + } else { + console.warn("❌ Could not find visible cell for hidden position") + return // Skip if we can't find a visible cell + } + } else { + console.log("✅ Target cell is visible, using directly") + } + } if (targetCell) { const displayValue = value !== undefined && value !== null ? String(value).trim() : '' console.log("Processing value:", displayValue) + console.log("Target cell before rotation:", targetCell.outerHTML) if (displayValue) { - // Apply rotation with improved styling - targetCell.innerHTML = `