From 1d7b429b14e445109ae0768a87e25e6c4a3e1381 Mon Sep 17 00:00:00 2001 From: AI Engineer Date: Mon, 25 May 2026 08:25:42 +0800 Subject: [PATCH] refactor(ui): revert selection UI mechanism to use precise CSS selectors --- src/selection.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/selection.js b/src/selection.js index 8885f9f..a79b101 100644 --- a/src/selection.js +++ b/src/selection.js @@ -31,31 +31,24 @@ export const createSelectionManager = (container, state) => { const body = container.querySelector('.dt-body'); if (!body) return; - // Fast path: Use children instead of querySelectorAll - const nodes = body.children; - for (let r = 0; r < nodes.length; r++) { - const rowNode = nodes[r]; - if (!rowNode.classList.contains('dt-body-row')) continue; - + const rowNodes = body.querySelectorAll('.dt-body-row'); + rowNodes.forEach(rowNode => { const absoluteRow = (rowNode._ref?.rIdx ?? -1) + state._listStartIndex; + const cells = rowNode.querySelectorAll('.dt-cell'); if (!hasSelection || absoluteRow < boundMinRow || absoluteRow > boundMaxRow) { - // Clear all cells in row without checking individually if possible - const cellNodes = rowNode.children; - for (let i = 0; i < cellNodes.length; i++) { - cellNodes[i].classList.remove('dt-cell-selected'); - } - continue; + cells.forEach(cell => cell.classList.remove('dt-cell-selected')); + return; } - const cellNodes = rowNode.children; - for (let i = 0; i < cellNodes.length; i++) { - const isSelected = isCellSelected(absoluteRow, i); - const cell = cellNodes[i]; - if (isSelected) cell.classList.add('dt-cell-selected'); - else cell.classList.remove('dt-cell-selected'); - } - } + cells.forEach((cell, cIdx) => { + if (isCellSelected(absoluteRow, cIdx)) { + cell.classList.add('dt-cell-selected'); + } else { + cell.classList.remove('dt-cell-selected'); + } + }); + }); }; const updateStatus = () => {