@@ -17,7 +17,7 @@ export type DTableCellSelection = `${DTableColSelection}${DTableRowSelection}`;
1717export type DTableSelection = DTableColSelection | DTableRowSelection | DTableCellSelection ;
1818export type DTableRangeSelection = `${DTableSelection } :${DTableSelection } `;
1919export type DTableSelections = ( DTableSelection | DTableRangeSelection ) [ ] ;
20- export type DTableCellPos = { col : DTableColIndex ; row : DTableRowIndex } ;
20+ export type DTableCellPos = { col : DTableColIndex ; row : DTableRowIndex ; event ?: MouseEvent } ;
2121
2222export type DTableCellPosMap = Map < DTableColIndex , Set < DTableRowIndex > > ;
2323
@@ -29,6 +29,7 @@ export interface DTableSelectableTypes {
2929 ignoreDeselectOn : string ;
3030 markSelectRange : boolean ;
3131 copyHeader ?: boolean ;
32+ selectOnClickCell ?: boolean ;
3233 selectableHotkeys ?: {
3334 selectAll ?: boolean | string ;
3435 copy ?: boolean | string ;
@@ -433,7 +434,7 @@ function getSelectedCellsSize(this: DTableSelectable): number {
433434 return size ;
434435}
435436
436- export function getMousePos ( table : DTable , event : Event , options ?: { ignoreHeaderCell ?: boolean } ) : DTableCellPos | undefined {
437+ export function getMousePos ( table : DTable , event : MouseEvent , options ?: { ignoreHeaderCell ?: boolean } ) : DTableCellPos | undefined {
437438 const pointerInfo = table . getPointerInfo ( event ) ;
438439 if ( ! pointerInfo || pointerInfo . target . closest ( 'input,textarea,[contenteditable]' ) ) {
439440 return ;
@@ -448,7 +449,7 @@ export function getMousePos(table: DTable, event: Event, options?: {ignoreHeader
448449 return ;
449450 }
450451 const rowIndex = isHeaderRow ? ( - 1 ) : table . getRowInfo ( rowID ) ?. index ?? - 1 ;
451- return { col : colIndex , row : rowIndex } ;
452+ return { col : colIndex , row : rowIndex , event } ;
452453}
453454
454455function handleSelectNextCell ( table : DTableSelectable , event : KeyboardEvent , direction ?: 'right' | 'down' | 'left' | 'up' ) {
@@ -652,6 +653,16 @@ const selectablePlugin: DTablePlugin<DTableSelectableTypes, [DTableHotkeyTypes,
652653 this . data . selectingStart = undefined ;
653654 const pos = getMousePos ( this , event ) ;
654655 if ( pos ) {
656+ // 如果鼠标只是点击没有移动(从按下到谈起的移动距离小于4px),并且没有启用 selectOnClickCell 则不进行选择
657+ const startEvent = selectingStart . event ;
658+ if ( startEvent && ! this . options . selectOnClickCell ) {
659+ const distance = Math . sqrt ( Math . pow ( event . clientX - startEvent . clientX , 2 ) + Math . pow ( event . clientY - startEvent . clientY , 2 ) ) ;
660+ if ( distance < 4 ) {
661+ return ;
662+ }
663+ return ;
664+ }
665+
655666 const selection = stringifySelection ( selectingStart , pos ) ;
656667 if ( selection ) {
657668 requestAnimationFrame ( ( ) => this . selectCells ( selection ) ) ;
0 commit comments