Commit af9778524d

af9778524d5dfc7063ef3bbbff5719fed052a143

parent: 7f8fa0e9dc

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-06-20 05:43 UTC

copy button fix for row span

Layout: unified · split

docs/.vitepress/theme/Layout.vue +39 −5
@@ -665,11 +665,45 @@ function initCopyButtonsInRoot(root: ParentNode) {
665 }) 665 })
666 if (manualColIndex === -1) return 666 if (manualColIndex === -1) return
667 667
668 // Track how many more rows each column is occupied by a rowspan from above
669 const colOccupied: number[] = []
670
668 table.querySelectorAll<HTMLTableRowElement>('tbody tr').forEach(row => { 671 table.querySelectorAll<HTMLTableRowElement>('tbody tr').forEach(row => {
669 const cell = row.querySelectorAll('td')[manualColIndex] 672 const cells = Array.from(row.querySelectorAll('td'))
670 if (!cell || cell.querySelector('.manual-copy-btn')) return 673 let cellIdx = 0
674 let col = 0
675 let manualCell: HTMLTableCellElement | null = null
676
677 while (col <= manualColIndex) {
678 // Column occupied by a rowspan from a previous row — skip it
679 if ((colOccupied[col] ?? 0) > 0) {
680 colOccupied[col]--
681 col++
682 continue
683 }
684
685 if (cellIdx >= cells.length) break
686 const cell = cells[cellIdx++]
687 const colspan = cell.colSpan || 1
688 const rowspan = cell.rowSpan || 1
689
690 // Register future occupation for rowspan > 1
691 if (rowspan > 1) {
692 for (let c = col; c < col + colspan; c++) {
693 colOccupied[c] = (colOccupied[c] ?? 0) + (rowspan - 1)
694 }
695 }
696
697 if (col <= manualColIndex && col + colspan > manualColIndex) {
698 manualCell = cell
699 }
700
701 col += colspan
702 }
703
704 if (!manualCell || manualCell.querySelector('.manual-copy-btn')) return
671 705
672 const link = cell.querySelector<HTMLAnchorElement>('a[href]') 706 const link = manualCell.querySelector<HTMLAnchorElement>('a[href]')
673 if (!link) return 707 if (!link) return
674 const url = link.getAttribute('href')! 708 const url = link.getAttribute('href')!
675 709
@@ -693,8 +727,8 @@ function initCopyButtonsInRoot(root: ParentNode) {
693 } catch {} 727 } catch {}
694 }) 728 })
695 729
696 cell.classList.add('has-manual-copy') 730 manualCell.classList.add('has-manual-copy')
697 cell.appendChild(btn) 731 manualCell.appendChild(btn)
698 }) 732 })
699 }) 733 })
700} 734}