Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2840 feature disable scroll when click cell #2885

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "feat: add select makeSelectCellVisible #2840\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
18 changes: 13 additions & 5 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
row: number,
isShift?: boolean,
isCtrl?: boolean,
makeSelectCellVisible: boolean = true,
makeSelectCellVisible?: boolean,
skipBodyMerge: boolean = false,
forceSelect: boolean = false
) {
Expand All @@ -2610,7 +2610,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
isShift,
isCtrl,
false,
!makeSelectCellVisible,
makeSelectCellVisible ?? this.options.select?.makeSelectCellVisible ?? true,
skipBodyMerge,
forceSelect
);
Expand All @@ -2630,7 +2630,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
false,
index >= 1,
false,
false,
this.options.select?.makeSelectCellVisible ?? true,
true
);
} else {
Expand All @@ -2640,11 +2640,19 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
false,
index >= 1,
false,
false,
this.options.select?.makeSelectCellVisible ?? true,
true
);
this.stateManager.updateInteractionState(InteractionState.grabing);
this.stateManager.updateSelectPos(cellRange.end.col, cellRange.end.row, false, index >= 1, false, false, true);
this.stateManager.updateSelectPos(
cellRange.end.col,
cellRange.end.row,
false,
index >= 1,
false,
this.options.select?.makeSelectCellVisible ?? true,
true
);
}
this.stateManager.endSelectCells(false, false);
this.stateManager.updateInteractionState(InteractionState.default);
Expand Down
6 changes: 3 additions & 3 deletions packages/vtable/src/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class EventManager {
eventArgs.event.shiftKey,
eventArgs.event.ctrlKey || eventArgs.event.metaKey,
false,
isSelectMoving
this.table.options.select?.makeSelectCellVisible ?? true
);

return true;
Expand Down Expand Up @@ -357,7 +357,7 @@ export class EventManager {
true,
eventArgs.event.ctrlKey || eventArgs.event.metaKey,
false,
isSelectMoving
!isSelectMoving
);
} else {
this.table.stateManager.updateSelectPos(
Expand All @@ -366,7 +366,7 @@ export class EventManager {
eventArgs.event.shiftKey,
eventArgs.event.ctrlKey || eventArgs.event.metaKey,
false,
isSelectMoving
!isSelectMoving
);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/event/listener/container-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ export function bindContainerDomListener(eventManager: EventManager) {
const targetCol = table.getTargetColAtConsiderRightFrozen(selectX, considerFrozenX);
const targetRow = table.getTargetRowAtConsiderBottomFrozen(selectY, considerFrozenY);
if (isValid(targetCol) && isValid(targetRow)) {
table.stateManager.updateSelectPos(targetCol.col, targetRow.row, false, false, false, true);
table.stateManager.updateSelectPos(targetCol.col, targetRow.row, false, false, false, false);
}
});
} else if (table.eventManager.inertiaScroll.isInertiaScrolling()) {
Expand Down
6 changes: 3 additions & 3 deletions packages/vtable/src/state/select/update-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function updateSelectPosition(
isShift: boolean,
isCtrl: boolean,
isSelectAll: boolean,
isSelectMoving: boolean = false,
makeSelectCellVisible: boolean = true,
skipBodyMerge: boolean = false,
forceSelect: boolean = false
) {
Expand All @@ -27,7 +27,7 @@ export function updateSelectPosition(
const { highlightScope, disableHeader, cellPos } = state.select;

if (((disableHeader && table.isHeader(col, row)) || highlightScope === 'none') && forceSelect === false) {
if (col !== -1 && row !== -1 && !isSelectMoving) {
if (col !== -1 && row !== -1 && makeSelectCellVisible) {
table._makeVisibleCell(col, row);
}
col = -1;
Expand All @@ -38,7 +38,7 @@ export function updateSelectPosition(
// return;
// }
/** 完整显示选中单元格 自动滚动效果*/
if (col !== -1 && row !== -1 && !isSelectMoving) {
if (col !== -1 && row !== -1 && makeSelectCellVisible) {
if (interactionState === InteractionState.grabing && state.select.ranges.length > 0) {
const currentRange = state.select.ranges[state.select.ranges.length - 1];
if (col > currentRange.start.col && col > currentRange.end.col) {
Expand Down
14 changes: 12 additions & 2 deletions packages/vtable/src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,24 @@ export class StateManager {
isShift: boolean = false,
isCtrl: boolean = false,
isSelectAll: boolean = false,
isSelectMoving: boolean = false,
makeSelectCellVisible: boolean = true,
skipBodyMerge: boolean = false,
forceSelect: boolean = false
) {
if (row !== -1 && row !== -1) {
this.select.selecting = true;
}
updateSelectPosition(this, col, row, isShift, isCtrl, isSelectAll, isSelectMoving, skipBodyMerge, forceSelect);
updateSelectPosition(
this,
col,
row,
isShift,
isCtrl,
isSelectAll,
makeSelectCellVisible,
skipBodyMerge,
forceSelect
);
}

checkCellRangeInSelect(cellPosStart: CellAddress, cellPosEnd: CellAddress) {
Expand Down
2 changes: 2 additions & 0 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ export interface BaseTableConstructorOptions {
disableDragSelect?: boolean;
/** 是否在选择多行或多列时高亮范围 */
highlightInRange?: boolean;
/** 是否将选中的单元格自动滚动到视口内 默认为true */
makeSelectCellVisible?: boolean;
};
/** 下拉菜单的相关配置。消失时机:显示后点击菜单区域外自动消失*/
menu?: {
Expand Down
Loading