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

fix: fix width and height cache clear timing when move cell #72

Merged
merged 1 commit into from
Jun 28, 2023
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
32 changes: 30 additions & 2 deletions packages/vtable/src/state/cell-move/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BaseTableAPI } from '../../ts-types/base-table';
import type { StateManeger } from '../state';
import { adjustMoveHeaderTarget } from './adjust-header';

Expand Down Expand Up @@ -89,6 +90,16 @@ export function endMoveCol(state: StateManeger) {
// state.targetCol - state.sourceCol,
// state.targetRow - state.sourceRow
// );

// clear columns width and rows height cache
clearWidthsAndHeightsCache(
state.columnMove.colSource,
state.columnMove.rowSource,
state.columnMove.colTarget,
state.columnMove.rowTarget,
state.table
);

// 更新状态
if (moveSuccess) {
state.table.scenegraph.updateHeaderPosition(
Expand All @@ -99,9 +110,26 @@ export function endMoveCol(state: StateManeger) {
);
}

// 清空列宽缓存
state.updateCursor();
(state.table as any)._colRangeWidthsMap.clear();
state.table.scenegraph.component.hideMoveCol();
state.table.scenegraph.updateNextFrame();
}

function clearWidthsAndHeightsCache(
colSource: number,
rowSource: number,
colTarget: number,
rowTarget: number,
table: BaseTableAPI
) {
const colMin = Math.min(colSource, colTarget);
const colMax = Math.max(colSource, colTarget);
const rowMin = Math.min(rowSource, rowTarget);
const rowMax = Math.max(rowSource, rowTarget);
for (let col = colMin; col <= colMax; col++) {
table._clearColRangeWidthsMap(col);
}
for (let row = rowMin; row <= rowMax; row++) {
table._clearRowRangeHeightsMap(row);
}
}
1 change: 1 addition & 0 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ export interface BaseTableAPI {
isPivotTable: (() => boolean) & (() => boolean);

_clearColRangeWidthsMap: (col?: number) => void;
_clearRowRangeHeightsMap: (row?: number) => void;

toggleHierarchyState: (col: number, row: number) => void;

Expand Down
Loading