From 972afc6c4cfc5192db753c1488f4ed852254ae13 Mon Sep 17 00:00:00 2001 From: YardWill Date: Tue, 9 Aug 2022 15:15:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(interaction):=20=E4=BC=98=E5=8C=96resetShee?= =?UTF-8?q?tStyle=E6=80=A7=E8=83=BD=20(#1653)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 优化reset性能 * fix: icon draw --- packages/s2-core/src/interaction/root.ts | 5 ++- .../src/utils/interaction/state-controller.ts | 38 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/s2-core/src/interaction/root.ts b/packages/s2-core/src/interaction/root.ts index 301901326a..73d9a73c46 100644 --- a/packages/s2-core/src/interaction/root.ts +++ b/packages/s2-core/src/interaction/root.ts @@ -445,8 +445,9 @@ export class RootInteraction { } public clearState() { - clearState(this.spreadsheet); - this.draw(); + if (clearState(this.spreadsheet)) { + this.draw(); + } } public changeState(interactionStateInfo: InteractionStateInfo) { diff --git a/packages/s2-core/src/utils/interaction/state-controller.ts b/packages/s2-core/src/utils/interaction/state-controller.ts index 822198918f..0365fdaf52 100644 --- a/packages/s2-core/src/utils/interaction/state-controller.ts +++ b/packages/s2-core/src/utils/interaction/state-controller.ts @@ -7,31 +7,37 @@ import type { SpreadSheet } from '../../sheet-type'; * @desc clear the interaction state information * @param spreadsheet sheet instance */ -export const clearState = (spreadsheet: SpreadSheet) => { +export const clearState = (spreadsheet: SpreadSheet): boolean => { const activeIcons = spreadsheet.store.get('visibleActionIcons'); + const allInteractedCells = spreadsheet.interaction.getInteractedCells(); + const cellMetas = spreadsheet.interaction.getState().cells; + // 如果都处于初始化状态 不需要clear + if ( + isEmpty(allInteractedCells) && + isEmpty(cellMetas) && + isEmpty(activeIcons) + ) { + return false; + } forEach(activeIcons, (icon) => { icon.set('visible', false); }); spreadsheet.store.set('visibleActionIcons', []); - const allInteractedCells = spreadsheet.interaction.getInteractedCells(); - const cellMetas = spreadsheet.interaction.getState().cells; - - if (!isEmpty(allInteractedCells) || !isEmpty(cellMetas)) { - forEach(allInteractedCells, (cell: S2CellType) => { - cell.hideInteractionShape(); - }); + forEach(allInteractedCells, (cell: S2CellType) => { + cell.hideInteractionShape(); + }); - spreadsheet.interaction.resetState(); - if (spreadsheet.options.interaction.selectedCellsSpotlight) { - const unSelectedCells = - spreadsheet.interaction.getPanelGroupAllUnSelectedDataCells() || []; + spreadsheet.interaction.resetState(); + if (spreadsheet.options.interaction.selectedCellsSpotlight) { + const unSelectedCells = + spreadsheet.interaction.getPanelGroupAllUnSelectedDataCells() || []; - forEach(unSelectedCells, (cell) => { - cell.clearUnselectedState(); - }); - } + forEach(unSelectedCells, (cell) => { + cell.clearUnselectedState(); + }); } + return true; }; /**