fix: HandsontablePro 选中行高亮按视觉行号匹配,修复滚动后点击高亮错行

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-10-19 18:59:12 +08:00
parent b178a2a35d
commit 6df8d8976d

View File

@ -2046,6 +2046,7 @@
};
removeFilterIconFromColumns();
syncHybridHeaders();
applySelectedRowStyles();
remasureActionColumnFromDom();
// remasure/updateSettings 后 HOT 会按原生滚动条再次缩短 clone,需再对齐一次
scheduleCloneOverlaySync();
@ -2443,15 +2444,14 @@
const tbody = hotContainer.value.querySelector('.ht_master tbody');
if (!tbody) return;
// HOT 虚拟滚动只渲染可视区行且复用 tr,DOM 下标 ≠ 视觉行号,须按单元格坐标取行
const rows = tbody.querySelectorAll('tr');
rows.forEach((row, index) => {
// 移除之前的所有选中状态
row.classList.remove('selected-row');
// 为当前选中的行添加类
if (selectedRowIndicesSet.value.has(index)) {
row.classList.add('selected-row');
}
rows.forEach((row) => {
const cell = row.querySelector('td, th') as HTMLTableCellElement | null;
const visualRow = cell ? hotInstance!.getCoords(cell)?.row : undefined;
const selected =
typeof visualRow === 'number' && visualRow >= 0 && selectedRowIndicesSet.value.has(visualRow);
row.classList.toggle('selected-row', selected);
});
};