feat: 为列号和行号单元格添加拖拽事件处理逻辑,增强用户交互体验 [FR] Drag to resize columns #20

This commit is contained in:
JayBridge 2025-06-19 21:07:42 +08:00
parent 8464338565
commit f197973c01
2 changed files with 20 additions and 0 deletions

View file

@ -355,6 +355,21 @@ export class CSVView extends TextFileView {
onMoveColLeft: (colIdx) => this.moveCol(colIdx, colIdx - 1),
onMoveColRight: (colIdx) => this.moveCol(colIdx, colIdx + 1),
});
// 在 refresh 方法中调用 setupColumnResize为列号和行号单元格绑定拖拽事件
this.tableData[0].forEach((_, index) => {
const resizeHandle = this.tableEl.querySelector(`.resize-handle[data-index='${index}']`) as HTMLElement;
if (resizeHandle) {
this.setupColumnResize(resizeHandle, index);
}
});
this.tableData.forEach((_, rowIndex) => {
const resizeHandleRow = this.tableEl.querySelector(`.resize-handle-row[data-row-index='${rowIndex}']`) as HTMLElement;
if (resizeHandleRow) {
this.setupColumnResize(resizeHandleRow, rowIndex);
}
});
}
// 新增获取列标签A, B, C, ... Z, AA, AB, ...

View file

@ -154,6 +154,10 @@ export function renderTable(options: TableRenderOptions) {
th.classList.add('csv-dragging-highlight');
}
}
// 在列号单元格中添加拖拽事件处理逻辑
const resizeHandle = th.createEl("div", { cls: "resize-handle" });
setupColumnResize(resizeHandle, index);
});
}
@ -184,6 +188,7 @@ export function renderTable(options: TableRenderOptions) {
headerInput.onfocus = (ev) => {
setActiveCell(0, index, ev.currentTarget as HTMLInputElement);
};
// 在列号单元格中添加拖拽事件处理逻辑
const resizeHandle = th.createEl("div", { cls: "resize-handle" });
setupColumnResize(resizeHandle, index);
});