diff --git a/packages/sheets-ui/src/controllers/selection.controller.ts b/packages/sheets-ui/src/controllers/selection.controller.ts index 2d9d45a76d2..06124ed3149 100644 --- a/packages/sheets-ui/src/controllers/selection.controller.ts +++ b/packages/sheets-ui/src/controllers/selection.controller.ts @@ -135,34 +135,19 @@ export class SelectionController extends Disposable { } this._refreshSelection(param); - - // this._selectionRenderService.reset(); - - // for (const selectionWithStyle of param) { - // if (selectionWithStyle == null) { - // continue; - // } - // const selectionData = - // this._selectionRenderService.convertSelectionRangeToData(selectionWithStyle); - // selectionData.style = getNormalSelectionStyle(this._themeService); - // this._selectionRenderService.addControlToCurrentByRangeData(selectionData); - // } }) ) ); } - private _refreshSelection(param: readonly ISelectionWithStyle[]) { - this._selectionRenderService.reset(); - - for (const selectionWithStyle of param) { - if (selectionWithStyle == null) { - continue; - } + private _refreshSelection(params: readonly ISelectionWithStyle[]) { + const selections = params.map((selectionWithStyle) => { const selectionData = this._selectionRenderService.convertSelectionRangeToData(selectionWithStyle); selectionData.style = getNormalSelectionStyle(this._themeService); - this._selectionRenderService.addControlToCurrentByRangeData(selectionData); - } + return selectionData; + }); + + this._selectionRenderService.updateControlForCurrentByRangeData(selections); } private _initRowHeader(sheetObject: ISheetObjectParam) { diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.ts index 1c9c26c0f27..7ab6d3aeb99 100644 --- a/packages/sheets-ui/src/services/selection/selection-render.service.ts +++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts @@ -67,6 +67,7 @@ export interface ISelectionRenderService { disableSkipRemainLast(): void; addControlToCurrentByRangeData(data: ISelectionWithCoordAndStyle): void; + updateControlForCurrentByRangeData(selections: ISelectionWithCoordAndStyle[]): void; changeRuntime(skeleton: SpreadsheetSkeleton, scene: Scene, viewport?: Viewport): void; getViewPort(): Viewport; getCurrentControls(): SelectionShape[]; @@ -295,6 +296,35 @@ export class SelectionRenderService implements ISelectionRenderService { currentControls.push(control); } + /** + * update selection + * @param selectionRange + * @param curCellRange + * @returns + */ + updateControlForCurrentByRangeData(selections: ISelectionWithCoordAndStyle[]) { + const currentControls = this.getCurrentControls(); + if (!currentControls) { + return; + } + + const skeleton = this._skeleton; + + if (skeleton == null) { + return; + } + + const { rowHeaderWidth, columnHeaderHeight } = skeleton; + + for (let i = 0, len = selections.length; i < len; i++) { + const { rangeWithCoord, primaryWithCoord, style } = selections[i]; + + const control = currentControls[i]; + + control.update(rangeWithCoord, rowHeaderWidth, columnHeaderHeight, style, primaryWithCoord); + } + } + refreshSelectionMoveStart() { this._selectionMoveStart$.next(this.getSelectionDataWithStyle()); }