Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: multi normal selections did not refresh when changing sheets. (#3166)
lumix1314465ba48f
diff --git a/packages/engine-render/src/components/sheets/sheet-skeleton.ts b/packages/engine-render/src/components/sheets/sheet-skeleton.tsindex eecdc99904..24c018a87e 100644--- a/packages/engine-render/src/components/sheets/sheet-skeleton.ts+++ b/packages/engine-render/src/components/sheets/sheet-skeleton.ts@@ -43,14 +43,17 @@ import type {IBorderStyleData,ICellData,IColumnData,+ IColumnRange,IDocumentData,IDocumentRenderConfig,IObjectArrayPrimitiveType,IPaddingData,+ IPosition,IRange,IRowAutoHeightInfo,IRowData,ISelectionCellWithMergeInfo,+ ISize,IStyleBase,IStyleData,ITextRotation,@@ -88,12 +91,12 @@ import type { BorderCache, IFontCacheItem, IStylesCache } from './interfaces';* @param documentSkeleton Data of the document's ViewModel* @param angleInDegree The rotation angle of an Excel cell, it's **degree***/-export function getDocsSkeletonPageSize(documentSkeleton: DocumentSkeleton, angleInDegree: number = 0) {+export function getDocsSkeletonPageSize(documentSkeleton: DocumentSkeleton, angleInDegree: number = 0): Nullable<Required<ISize>> {const skeletonData = documentSkeleton?.getSkeletonData();const angle = degToRad(angleInDegree);if (!skeletonData) {- return;+ return null;}const { pages } = skeletonData;const lastPage = pages[pages.length - 1];@@ -269,62 +272,62 @@ export class SpreadsheetSkeleton extends Skeleton {// this.updateDataMerge();}- get rowHeightAccumulation() {+ get rowHeightAccumulation(): number[] {return this._rowHeightAccumulation;}- get rowTotalHeight() {+ get rowTotalHeight(): number {return this._rowTotalHeight;}- get columnWidthAccumulation() {+ get columnWidthAccumulation(): number[] {return this._columnWidthAccumulation;}- get columnTotalWidth() {+ get columnTotalWidth(): number {return this._columnTotalWidth;}- get rowHeaderWidth() {+ get rowHeaderWidth(): number {return this._rowHeaderWidth;}- get columnHeaderHeight() {+ get columnHeaderHeight(): number {return this._columnHeaderHeight;}/*** row col start & end range*/- get rowColumnSegment() {+ get rowColumnSegment(): IRowColumnSegment {return this._rowColumnSegment;}- get dataMergeCache() {+ get dataMergeCache(): IRange[] {return this._dataMergeCache;}- get stylesCache() {+ get stylesCache(): IStylesCache {return this._stylesCache;}- get overflowCache() {+ get overflowCache(): ObjectMatrix<IRange> {return this._overflowCache;}- get showGridlines() {+ get showGridlines(): BooleanNumber {return this._showGridlines;}- get mergeData() {+ get mergeData(): IRange[] {return this._worksheetData.mergeData;}- get rowHeaderWidthAndMarginLeft() {+ get rowHeaderWidthAndMarginLeft(): number {return this.rowHeaderWidth + this._marginLeft;}- get columnHeaderHeightAndMarginTop() {+ get columnHeaderHeightAndMarginTop(): number {return this.columnHeaderHeight + this._marginTop;}@@ -351,7 +354,7 @@ export class SpreadsheetSkeleton extends Skeleton {/*** @deprecated should never expose a property that is provided by another module!*/- getsStyles() {+ getsStyles(): Styles {return this._styles;}@@ -363,7 +366,7 @@ export class SpreadsheetSkeleton extends Skeleton {return [this.worksheet.getUnitId(), this.worksheet.getSheetId()];}- private _initContextListener() {+ private _initContextListener(): void {this.disposeWithMe(this._contextService.subscribeContextValue$(RENDER_RAW_FORMULA_KEY).pipe(startWith(false),@@ -376,27 +379,27 @@ export class SpreadsheetSkeleton extends Skeleton {);}- setOverflowCache(value: ObjectMatrix<IRange>) {+ setOverflowCache(value: ObjectMatrix<IRange>): void {this._overflowCache = value;}- setMarginLeft(left: number) {+ setMarginLeft(left: number): void {this._marginLeft = left;}- setMarginTop(top: number) {+ setMarginTop(top: number): void {this._marginTop = top;}- calculateSegment(bounds?: IViewportInfo) {+ calculateSegment(bounds?: IViewportInfo): boolean {if (!this._worksheetData) {- return;+ return false;}this._updateLayout();if (!this._rowHeightAccumulation || !this._columnWidthAccumulation) {- return;+ return false;}if (bounds != null) {@@ -406,7 +409,7 @@ export class SpreadsheetSkeleton extends Skeleton {return true;}- calculateWithoutClearingCache(bounds?: IViewportInfo) {+ calculateWithoutClearingCache(bounds?: IViewportInfo): Nullable<SpreadsheetSkeleton> {if (!this.calculateSegment(bounds)) {return;}@@ -420,7 +423,7 @@ export class SpreadsheetSkeleton extends Skeleton {return this;}- calculate(bounds?: IViewportInfo) {+ calculate(bounds?: IViewportInfo): Nullable<SpreadsheetSkeleton> {this._resetCache();this.calculateWithoutClearingCache(bounds);@@ -428,7 +431,7 @@ export class SpreadsheetSkeleton extends Skeleton {return this;}- calculateAutoHeightInRange(ranges: Nullable<IRange[]>) {+ calculateAutoHeightInRange(ranges: Nullable<IRange[]>): IRowAutoHeightInfo[] {if (!Tools.isArray(ranges)) {return [];}@@ -544,9 +547,8 @@ export class SpreadsheetSkeleton extends Skeleton {/*** Calculate data for row col & cell position, then update position value to this._rowHeaderWidth & this._rowHeightAccumulation & this._columnHeaderHeight & this._columnWidthAccumulation.- * @returns this*/- private _updateLayout() {+ private _updateLayout(): void {if (!this.dirty) {return;}@@ -583,8 +585,6 @@ export class SpreadsheetSkeleton extends Skeleton {this._showGridlines = showGridlines;this.makeDirty(false);-- return this;}private _dynamicallyUpdateRowHeaderWidth(rowHeader: { width: number }): number {@@ -593,7 +593,7 @@ export class SpreadsheetSkeleton extends Skeleton {return Math.max(rowHeader.width, widthByComputation);}- getRowColumnSegment(bounds?: IViewportInfo) {+ getRowColumnSegment(bounds?: IViewportInfo): IRange {return this._getBounding(this._rowHeightAccumulation, this._columnWidthAccumulation, bounds?.cacheBound);// return this._getBounding(this._rowHeightAccumulation, this._columnWidthAccumulation, bounds?.viewBound);}@@ -602,11 +602,11 @@ export class SpreadsheetSkeleton extends Skeleton {* @deprecated should never expose a property that is provided by another module!* @returns*/- getWorksheetConfig() {+ getWorksheetConfig(): IWorksheetData {return this._worksheetData;}- getRowColumnSegmentByViewBound(bound?: IBoundRectNoAngle) {+ getRowColumnSegmentByViewBound(bound?: IBoundRectNoAngle): IRange {return this._getBounding(this._rowHeightAccumulation, this._columnWidthAccumulation, bound);}@@ -674,7 +674,7 @@ export class SpreadsheetSkeleton extends Skeleton {};}- appendToOverflowCache(row: number, column: number, startColumn: number, endColumn: number) {+ appendToOverflowCache(row: number, column: number, startColumn: number, endColumn: number): void {this._overflowCache.setValue(row, column, {startRow: row,endRow: row,@@ -683,22 +683,22 @@ export class SpreadsheetSkeleton extends Skeleton {});}- getColumnCount() {+ getColumnCount(): number {return this._columnWidthAccumulation.length;}- getRowCount() {+ getRowCount(): number {return this._rowHeightAccumulation.length;}getOverflowPosition(- contentSize: { width: number; height: number },+ contentSize: Required<ISize>,horizontalAlign: HorizontalAlign,row: number,column: number,columnCount: number- ) {- const { width: contentWidth } = contentSize;+ ): IColumnRange {+ const contentWidth = contentSize?.width ?? 0;let startColumn = column;let endColumn = column;@@ -720,7 +720,7 @@ export class SpreadsheetSkeleton extends Skeleton {};}- getNoMergeCellPositionByIndex(rowIndex: number, columnIndex: number) {+ getNoMergeCellPositionByIndex(rowIndex: number, columnIndex: number): IPosition {const {rowHeightAccumulation,columnWidthAccumulation,@@ -761,7 +761,7 @@ export class SpreadsheetSkeleton extends Skeleton {};}- getNoMergeCellPositionByIndexWithNoHeader(rowIndex: number, columnIndex: number) {+ getNoMergeCellPositionByIndexWithNoHeader(rowIndex: number, columnIndex: number): IPosition {const { rowHeightAccumulation, columnWidthAccumulation } = this;const { startY, endY, startX, endX } = getCellPositionByIndex(@@ -780,7 +780,7 @@ export class SpreadsheetSkeleton extends Skeleton {}/**- *+ * Get cell by pos(offsetX, offsetY).* @param offsetX HTML coordinate system, mouse position x.* @param offsetY HTML coordinate system, mouse position y.* @param scaleX render scene scale x-axis, scene.getAncestorScale@@ -820,9 +820,8 @@ export class SpreadsheetSkeleton extends Skeleton {scaleY: number,scrollXY: { x: number; y: number },closeFirst?: boolean- ) {+ ): { row: number; column: number } {const row = this.getRowPositionByOffsetY(offsetY, scaleY, scrollXY, closeFirst);-const column = this.getColumnPositionByOffsetX(offsetX, scaleX, scrollXY, closeFirst);return {@@ -839,7 +838,7 @@ export class SpreadsheetSkeleton extends Skeleton {* @returns*/- getColumnPositionByOffsetX(offsetX: number, scaleX: number, scrollXY: { x: number; y: number }, closeFirst?: boolean) {+ getColumnPositionByOffsetX(offsetX: number, scaleX: number, scrollXY: { x: number; y: number }, closeFirst?: boolean): number {offsetX = this.getTransformOffsetX(offsetX, scaleX, scrollXY);const { columnWidthAccumulation } = this;@@ -870,7 +869,7 @@ export class SpreadsheetSkeleton extends Skeleton {* @param scrollXY.x* @param scrollXY.y*/- getRowPositionByOffsetY(offsetY: number, scaleY: number, scrollXY: { x: number; y: number }, closeFirst?: boolean) {+ getRowPositionByOffsetY(offsetY: number, scaleY: number, scrollXY: { x: number; y: number }, closeFirst?: boolean): number {const { rowHeightAccumulation } = this;offsetY = this.getTransformOffsetY(offsetY, scaleY, scrollXY);@@ -893,7 +892,7 @@ export class SpreadsheetSkeleton extends Skeleton {return row;}- getTransformOffsetX(offsetX: number, scaleX: number, scrollXY: { x: number; y: number }) {+ getTransformOffsetX(offsetX: number, scaleX: number, scrollXY: { x: number; y: number }): number {const { x: scrollX } = scrollXY;// so we should map physical positions to ideal positions@@ -902,7 +901,7 @@ export class SpreadsheetSkeleton extends Skeleton {return offsetX;}- getTransformOffsetY(offsetY: number, scaleY: number, scrollXY: { x: number; y: number }) {+ getTransformOffsetY(offsetY: number, scaleY: number, scrollXY: { x: number; y: number }): number {const { y: scrollY } = scrollXY;// these values are not affected by zooming (ideal positions)@@ -927,7 +926,7 @@ export class SpreadsheetSkeleton extends Skeleton {return columnWidthAccumulation[lastColumnIndex] + rowHeaderWidthAndMarginLeft;}- getOffsetByPositionY(row: number) {+ getOffsetByPositionY(row: number): number {const { rowHeightAccumulation, columnHeaderHeightAndMarginTop } = this;const lastRowIndex = rowHeightAccumulation.length - 1;const rowValue = rowHeightAccumulation[row];@@ -985,7 +984,7 @@ export class SpreadsheetSkeleton extends Skeleton {};}- getCellByIndexWithNoHeader(row: number, column: number) {+ getCellByIndexWithNoHeader(row: number, column: number): ISelectionCellWithMergeInfo {const { rowHeightAccumulation, columnWidthAccumulation } = this;const primary = getCellByIndex(@@ -1014,7 +1013,7 @@ export class SpreadsheetSkeleton extends Skeleton {}// convert canvas content position to physical position in screen- convertTransformToOffsetX(offsetX: number, scaleX: number, scrollXY: { x: number; y: number }) {+ convertTransformToOffsetX(offsetX: number, scaleX: number, scrollXY: { x: number; y: number }): number {const { x: scrollX } = scrollXY;offsetX = (offsetX - scrollX) * scaleX;@@ -1023,7 +1022,7 @@ export class SpreadsheetSkeleton extends Skeleton {}// convert canvas content position to physical position in screen- convertTransformToOffsetY(offsetY: number, scaleY: number, scrollXY: { x: number; y: number }) {+ convertTransformToOffsetY(offsetY: number, scaleY: number, scrollXY: { x: number; y: number }): number {const { y: scrollY } = scrollXY;offsetY = (offsetY - scrollY) * scaleY;@@ -1074,7 +1073,7 @@ export class SpreadsheetSkeleton extends Skeleton {}// Only used for cell edit, and no need to rotate text when edit cell content!- getCellDocumentModelWithFormula(cell: ICellData) {+ getCellDocumentModelWithFormula(cell: ICellData): Nullable<IDocumentLayoutObject> {return this._getCellDocumentModel(cell, {isDeepClone: true,displayRawFormula: true,@@ -1171,7 +1170,7 @@ export class SpreadsheetSkeleton extends Skeleton {};}- getDecomposedOffset(offsetX: number, offsetY: number) {+ getDecomposedOffset(offsetX: number, offsetY: number): { row: number; column: number; columnOffset: number; rowOffset: number } {let column = searchArray(this._columnWidthAccumulation, offsetX);let columnOffset = 0;if (column === -1 || column === 0) {@@ -1203,7 +1202,7 @@ export class SpreadsheetSkeleton extends Skeleton {* Overflow on the left or right is aligned according to the text's horizontal alignment.*/// eslint-disable-next-line complexity- private _calculateOverflowCell(row: number, column: number, docsConfig: IFontCacheItem) {+ private _calculateOverflowCell(row: number, column: number, docsConfig: IFontCacheItem): boolean {// wrap and angle handlerconst { documentSkeleton, vertexAngle = 0, centerAngle = 0, horizontalAlign, wrapStrategy } = docsConfig;@@ -1314,6 +1313,7 @@ export class SpreadsheetSkeleton extends Skeleton {this.appendToOverflowCache(row, column, startColumn, endColumn);}+ return false;}/**@@ -1327,7 +1327,7 @@ export class SpreadsheetSkeleton extends Skeleton {rowHeightAccumulation: number[],columnWidthAccumulation: number[],viewBound?: IBoundRectNoAngle- ) {+ ): IRange {const rhaLength = rowHeightAccumulation.length;const cwaLength = columnWidthAccumulation.length;@@ -1401,7 +1401,7 @@ export class SpreadsheetSkeleton extends Skeleton {rowCount: number,rowData: IObjectArrayPrimitiveType<Partial<IRowData>>,defaultRowHeight: number- ) {+ ): { rowTotalHeight: number; rowHeightAccumulation: number[] } {let rowTotalHeight = 0;const rowHeightAccumulation: number[] = [];const data = rowData;@@ -1443,7 +1443,7 @@ export class SpreadsheetSkeleton extends Skeleton {colCount: number,columnData: IObjectArrayPrimitiveType<Partial<IColumnData>>,defaultColumnWidth: number- ) {+ ): { columnTotalWidth: number; columnWidthAccumulation: number[] } {let columnTotalWidth = 0;const columnWidthAccumulation: number[] = [];@@ -1479,13 +1479,14 @@ export class SpreadsheetSkeleton extends Skeleton {};}+ //eslint-disable-next-line complexityprivate _getOverflowBound(row: number,startColumn: number,endColumn: number,contentWidth: number,horizontalAlign = HorizontalAlign.LEFT- ) {+ ): number {let cumWidth = 0;if (startColumn > endColumn) {const columnCount = this._columnWidthAccumulation.length - 1;@@ -1548,7 +1549,7 @@ export class SpreadsheetSkeleton extends Skeleton {return endColumn;}- intersectMergeRange(row: number, column: number) {+ intersectMergeRange(row: number, column: number): boolean {const dataMergeCache = this.dataMergeCache;for (const dataCache of dataMergeCache) {const {@@ -1588,7 +1589,7 @@ export class SpreadsheetSkeleton extends Skeleton {// return mergeRangeCache;// }- private _calculateStylesCache() {+ private _calculateStylesCache(): void {const dataMergeCaches = this._dataMergeCache;const rowColumnSegment = this._rowColumnSegment;const columnWidthAccumulation = this.columnWidthAccumulation;@@ -1806,7 +1807,7 @@ export class SpreadsheetSkeleton extends Skeleton {documentData: IDocumentData,horizontalAlign: HorizontalAlign,renderConfig?: IDocumentRenderConfig- ) {+ ): Nullable<DocumentDataModel> {if (!renderConfig) {return;}@@ -1840,7 +1841,7 @@ export class SpreadsheetSkeleton extends Skeleton {return new DocumentDataModel(documentData);}- private _getDocumentDataByStyle(content: string, textStyle: ITextStyle, config: ICellOtherConfig) {+ private _getDocumentDataByStyle(content: string, textStyle: ITextStyle, config: ICellOtherConfig): DocumentDataModel {const contentLength = content.length;const {textRotation,@@ -1909,7 +1910,7 @@ export class SpreadsheetSkeleton extends Skeleton {* pro/issues/344* In Excel, for the border rendering of merged cells to take effect, the outermost cells need to have the same border style.*/- private _setMergeBorderProps(type: BORDER_TYPE, cache: IStylesCache, mergeRange: IRange) {+ private _setMergeBorderProps(type: BORDER_TYPE, cache: IStylesCache, mergeRange: IRange): void {if (!this.worksheet || !cache.border) {return;}@@ -1995,10 +1996,10 @@ export class SpreadsheetSkeleton extends Skeleton {}}- private _setBorderProps(r: number, c: number, type: BORDER_TYPE, style: IStyleData, cache: IStylesCache) {+ private _setBorderProps(r: number, c: number, type: BORDER_TYPE, style: IStyleData, cache: IStylesCache): void {const props: Nullable<IBorderStyleData> = style.bd?.[type];if (!props || !cache.border) {- return true;+ return;}const rgb = getColorStyle(props.cl) || COLOR_BLACK_RGB;@@ -2017,12 +2018,12 @@ export class SpreadsheetSkeleton extends Skeleton {if (type === BORDER_TYPE.TOP) {const borderBottom = borderCache.getValue(r - 1, c)?.[BORDER_TYPE.BOTTOM];if (borderBottom && isWhiteColor(rgb)) {- return true;+ return;}} else if (type === BORDER_TYPE.LEFT) {const borderRight = borderCache.getValue(r, c - 1)?.[BORDER_TYPE.RIGHT];if (borderRight && isWhiteColor(rgb)) {- return true;+ return;}}@@ -2050,7 +2051,7 @@ export class SpreadsheetSkeleton extends Skeleton {return style;}- private _getOtherStyle(format?: Nullable<IStyleData>) {+ private _getOtherStyle(format?: Nullable<IStyleData>): ICellOtherConfig {if (!format) {return {};}@@ -2076,7 +2077,7 @@ export class SpreadsheetSkeleton extends Skeleton {verticalAlign,wrapStrategy,paddingData,- };+ } as ICellOtherConfig;}/**@@ -2084,7 +2085,7 @@ export class SpreadsheetSkeleton extends Skeleton {* @param mergeData all marge data* @param rowColumnSegment current screen range, include row and column*/- private _getMergeCells(mergeData: IRange[], rowColumnSegment?: IRowColumnSegment) {+ private _getMergeCells(mergeData: IRange[], rowColumnSegment?: IRowColumnSegment): IRange[] {// const rowColumnSegment = this._rowColumnSegment;const endColumnLast = this.columnWidthAccumulation.length - 1;if (!rowColumnSegment) {diff --git a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts b/packages/sheets-formula/src/controllers/formula-editor-show.controller.tsindex 8488b971d1..0e0162dc61 100644--- a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts@@ -15,8 +15,7 @@*/import type { ICellDataForSheetInterceptor, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IRowAutoHeightInfo, Nullable, Workbook, Worksheet } from '@univerjs/core';-import { ColorKit,- Disposable,+import { ColorKit, Disposable,ICommandService,ILogService,Inject,@@ -73,7 +72,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo// Do not intercept v:null and add t: CellValueType.NUMBER. When the cell =TODAY() is automatically filled, the number format will recognize the Number type and parse it as 1900-01-00 date format.}- private _initSkeletonChangeListener() {+ private _initSkeletonChangeListener(): void {this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {if (param == null) {@@ -92,11 +91,11 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo);}- protected _changeRuntime(skeleton: SpreadsheetSkeleton) {+ protected _changeRuntime(skeleton: SpreadsheetSkeleton): void {this._skeleton = skeleton;}- private _initInterceptorEditorStart() {+ private _initInterceptorEditorStart(): void {this.disposeWithMe(toDisposable(this._editorBridgeService.interceptor.intercept(@@ -158,7 +157,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo);}- private _commandExecutedListener() {+ private _commandExecutedListener(): void {this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo, options) => {if (command.id === SetFormulaCalculationResultMutation.id || (command.id === SetArrayFormulaDataMutation.id && options && options.remove)) {@@ -187,7 +186,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo);}- private _displayArrayFormulaRangeShape(matrixRange: IObjectMatrixPrimitiveType<IRange>, row: number, col: number, unitId: string, subUnitId: string, worksheet: Worksheet, cellInfo: Nullable<ICellDataForSheetInterceptor>) {+ private _displayArrayFormulaRangeShape(matrixRange: IObjectMatrixPrimitiveType<IRange>, row: number, col: number, unitId: string, subUnitId: string, worksheet: Worksheet, cellInfo: Nullable<ICellDataForSheetInterceptor>): Nullable<ICellDataForSheetInterceptor> {new ObjectMatrix(matrixRange).forValue((rowIndex, columnIndex, range) => {if (range == null) {return true;@@ -230,7 +229,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMoreturn cellInfo;}- private _createArrayFormulaRangeShape(arrayRange: IRange, unitId: string) {+ private _createArrayFormulaRangeShape(arrayRange: IRange, unitId: string): void {const styleSheet = this._themeService.getCurrentTheme();const fill = new ColorKit(styleSheet.colorWhite).setAlpha(0).toString();const style = {@@ -264,7 +263,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMothis._previousShape = control;}- private _removeArrayFormulaRangeShape() {+ private _removeArrayFormulaRangeShape(): void {if (this._previousShape == null) {return;}@@ -272,7 +271,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMothis._previousShape = null;}- private _refreshArrayFormulaRangeShape(unitId: string, range: IRange) {+ private _refreshArrayFormulaRangeShape(unitId: string, range: IRange): void {if (this._previousShape) {const { startRow, endRow, startColumn, endColumn } = this._previousShape.getRange();const range = { startRow, endRow, startColumn, endColumn };@@ -281,7 +280,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo}}- private _checkCurrentSheet(unitId: string, subUnitId: string) {+ private _checkCurrentSheet(unitId: string, subUnitId: string): boolean {const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();if (!skeleton) return false;@@ -295,7 +294,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMoreturn false;}- private _refreshArrayFormulaRangeShapeByRanges(unitId: string, subUnitId: string, ranges: IRange[]) {+ private _refreshArrayFormulaRangeShapeByRanges(unitId: string, subUnitId: string, ranges: IRange[]): void {if (!this._checkCurrentSheet(unitId, subUnitId)) return;if (!this._previousShape) return;@@ -325,7 +324,7 @@ export class FormulaEditorShowController extends Disposable implements IRenderMo}}- private _refreshArrayFormulaRangeShapeByRow(unitId: string, subUnitId: string, rowAutoHeightInfo: IRowAutoHeightInfo[]) {+ private _refreshArrayFormulaRangeShapeByRow(unitId: string, subUnitId: string, rowAutoHeightInfo: IRowAutoHeightInfo[]): void {if (!this._checkCurrentSheet(unitId, subUnitId)) return;if (!this._previousShape) return;diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.tsindex bfa3af2ffe..311f46b3d2 100644--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts@@ -847,12 +847,7 @@ export class EditingRenderController extends Disposable implements IRenderModulethis._commandService.syncExecuteCommand(SetSelectionsOperation.id, {unitId: this._context.unit.getUnitId(),subUnitId: worksheetId,-- // must be a new selectionData- // in selection-manager.service.ts@setSelections- // this._ensureWorkbookSelection(unitIdOrSelections).setSelections- // would clear selection Data on selecitonManagerInstance.- selections: [...selections],+ selections,});}diff --git a/packages/sheets-ui/src/services/selection/base-selection-render.service.ts b/packages/sheets-ui/src/services/selection/base-selection-render.service.tsindex 8b186bc17b..91351770b5 100644--- a/packages/sheets-ui/src/services/selection/base-selection-render.service.ts+++ b/packages/sheets-ui/src/services/selection/base-selection-render.service.ts@@ -15,6 +15,7 @@*/import type {+ IFreeze,IInterceptor,Injector,IRange,@@ -150,7 +151,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSeleprivate _selectionMoving = false;- get selectionMoving() {+ get selectionMoving(): boolean {return this._selectionMoving;}@@ -170,7 +171,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSelethis._initMoving();}- private _initMoving() {+ private _initMoving(): void {this.disposeWithMe(this._selectionMoving$.subscribe(() => {this._selectionMoving = true;}));@@ -180,19 +181,19 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele}));}- protected _setSelectionStyle(style: ISelectionStyle) {+ protected _setSelectionStyle(style: ISelectionStyle): void {this._selectionStyle = style;}/*** Reset this._selectionStyle to default normal selection style*/- protected _resetSelectionStyle() {+ protected _resetSelectionStyle(): void {this._setSelectionStyle(getDefaultNormalSelectionStyle(this._themeService));}/** @deprecated This should not be provided by the selection render service. */- getViewPort() {+ getViewPort(): Viewport {return this._activeViewport!;}@@ -204,7 +205,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele* Add a selection in spreadsheet, create a new SelectionControl and then update this control by range derives from selection.* @param {ISelectionWithCoordAndStyle} selection*/- protected _addSelectionControlBySelectionData(selection: ISelectionWithCoordAndStyle) {+ protected _addSelectionControlBySelectionData(selection: ISelectionWithCoordAndStyle): void {const skeleton = this._skeleton;const style = selection.style ?? getDefaultNormalSelectionStyle(this._themeService);const scene = this._scene;@@ -219,7 +220,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele// TODO: memory leak? This extension seems never released.// eslint-disable-next-line no-newnew SelectionShapeExtension(control, skeleton, scene, this._themeService, this._injector, {- selectionMoveEnd: () => {+ selectionMoveEnd: (): void => {this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());},});@@ -243,7 +244,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele* selectionData[i] syncs selectionControls[i]* @param selections*/- updateControlForCurrentByRangeData(selections: ISelectionWithCoordAndStyle[]) {+ updateControlForCurrentByRangeData(selections: ISelectionWithCoordAndStyle[]): void {const selectionControls = this.getSelectionControls();if (!selectionControls) {return;@@ -271,17 +272,17 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele}}- refreshSelectionMoveStart() {+ refreshSelectionMoveStart(): void {this._selectionMoveStart$.next(this.getSelectionDataWithStyle());}- protected _changeRuntime(skeleton: SpreadsheetSkeleton, scene: Scene, viewport?: Viewport) {+ protected _changeRuntime(skeleton: SpreadsheetSkeleton, scene: Scene, viewport?: Viewport): void {this._skeleton = skeleton;this._scene = scene;this._activeViewport = viewport || scene?.getViewports()[0];}- getSkeleton() {+ getSkeleton(): SpreadsheetSkeleton {return this._skeleton;}@@ -300,11 +301,11 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele});}- getSelectionControls() {+ getSelectionControls(): SelectionControl[] {return this._selectionControls;}- protected _clearSelectionControls() {+ protected _clearSelectionControls(): void {const allSelectionControls = this._selectionControls;for (const control of allSelectionControls) {control.dispose();@@ -313,12 +314,12 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSelethis._selectionControls.length = 0; // clear currentSelectionControls}- protected _getFreeze() {+ protected _getFreeze(): Nullable<IFreeze> {const freeze = this._sheetSkeletonManagerService.getCurrent()?.skeleton.getWorksheetConfig().freeze;return freeze;}- protected _getViewportByCell(row?: number, column?: number) {+ protected _getViewportByCell(row?: number, column?: number): Nullable<Viewport> {if (row === undefined || column === undefined) {return null;}@@ -371,7 +372,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele}}- endSelection() {+ endSelection(): void {this._clearUpdatingListeners();this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());// when selection mouse up, enable the short cut service@@ -381,7 +382,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele/*** Clear existed selections.*/- protected _reset() {+ protected _reset(): void {this._clearSelectionControls();this._downObserver?.unsubscribe();this._downObserver = null;@@ -723,7 +724,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSeleoffsetY: number,activeSelectionControl: Nullable<SelectionControl>,rangeType: RANGE_TYPE- ) {+ ): void {const skeleton = this._skeleton;const scene = this._scene;const [unitId, sheetId] = skeleton.getLocation();@@ -756,7 +757,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSeleconst cursorCellRangeInfo = this._getCellRangeByCursorPosition(offsetX, offsetY, scaleX, scaleY, scrollXY);if (!cursorCellRangeInfo) {- return false;+ return;}const { rangeWithCoord: cursorCellRange } = cursorCellRangeInfo;@@ -774,7 +775,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele}if (!newSelectionRange) {- return false;+ return;}const startCellXY = skeleton.getNoMergeCellPositionByIndex(newSelectionRange.startRow, newSelectionRange.startColumn);@@ -811,7 +812,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele* @param newSelectionRange* @param highlight*/- protected _updateSelectionControlByRange(control: SelectionControl, newSelectionRange: IRangeWithCoord, highlight: Nullable<ISelectionCellWithMergeInfo>) {+ protected _updateSelectionControlByRange(control: SelectionControl, newSelectionRange: IRangeWithCoord, highlight: Nullable<ISelectionCellWithMergeInfo>): void {// const skeleton = this._skeleton;// const { rowHeaderWidth, columnHeaderHeight } = skeleton;@@ -821,7 +822,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSelecontrol.updateRange(newSelectionRange, highlight);}- protected _clearUpdatingListeners() {+ protected _clearUpdatingListeners(): void {const scene = this._scene;scene.enableEvent();@@ -836,7 +837,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSelethis._scrollTimer?.dispose();}- protected _addEndingListeners() {+ protected _addEndingListeners(): void {const scene = this._scene!;const mainScene = scene.getEngine()?.activeScene;if (!mainScene || mainScene === scene) {@@ -924,7 +925,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele};}- protected _checkClearPreviousControls(evt: IPointerEvent | IMouseEvent) {+ protected _checkClearPreviousControls(evt: IPointerEvent | IMouseEvent): void {const curControls = this.getSelectionControls();if (curControls.length === 0) return;@@ -1000,7 +1001,7 @@ export class BaseSelectionRenderService extends Disposable implements ISheetSele* Reset all this.selectionControls by selectionsData.* @param selectionsData*/- protected _refreshSelectionControl(selectionsData: readonly ISelectionWithStyle[]) {+ protected _refreshSelectionControl(selectionsData: readonly ISelectionWithStyle[]): void {const selections = selectionsData.map((selectionWithStyle) => {const selectionData = attachSelectionWithCoord(selectionWithStyle, this._skeleton);selectionData.style = getDefaultNormalSelectionStyle(this._themeService);@@ -1019,12 +1020,12 @@ export function getAllSelection(skeleton: SpreadsheetSkeleton): ISelectionWithStendColumn: skeleton.getColumnCount() - 1,rangeType: RANGE_TYPE.ALL,},- primary: getTopLeftSelection(skeleton).primary,+ primary: getTopLeftSelection(skeleton)!.primary,style: null,};}-export function getTopLeftSelection(skeleton: SpreadsheetSkeleton) {+export function getTopLeftSelection(skeleton: SpreadsheetSkeleton): Nullable<ISelectionWithStyle> {const mergeData = skeleton.mergeData;return (transformCellDataToSelectionData(0, 0, mergeData) || {diff --git a/packages/sheets-ui/src/services/selection/selection-render.service.ts b/packages/sheets-ui/src/services/selection/selection-render.service.tsindex f4f9352aa9..002661bfd7 100644--- a/packages/sheets-ui/src/services/selection/selection-render.service.ts+++ b/packages/sheets-ui/src/services/selection/selection-render.service.ts@@ -61,7 +61,7 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService implthis._init();}- private _init() {+ private _init(): void {const sheetObject = this._getSheetObject();this._initEventListeners(sheetObject);@@ -131,7 +131,7 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService impl}));}- private _initThemeChangeListener() {+ private _initThemeChangeListener(): void {this.disposeWithMe(this._themeService.currentTheme$.subscribe(() => {this._resetSelectionStyle();const selections = this._workbookSelections.getCurrentSelections();@@ -145,7 +145,7 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService implreturn this._contextService.getContextValue(DISABLE_NORMAL_SELECTIONS);}- private _initSelectionChangeListener() {+ private _initSelectionChangeListener(): void {// When selection completes, we need to update the selections' rendering and clear event handlers.this.disposeWithMe(this._workbookSelections.selectionMoveEnd$.subscribe((params) => {this._reset();@@ -156,7 +156,7 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService impl}));}- private _initUserActionSyncListener() {+ private _initUserActionSyncListener(): void {this.disposeWithMe(this.selectionMoveStart$.subscribe((params) => this._updateSelections(params, SelectionMoveType.MOVE_START)));this.disposeWithMe(this.selectionMoving$.subscribe((params) => this._updateSelections(params, SelectionMoveType.MOVING)));@@ -199,7 +199,7 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService impl});}- private _initSkeletonChangeListener() {+ private _initSkeletonChangeListener(): void {// changing sheet is not the only way cause currentSkeleton$ emit, a lot of cmds will emit currentSkeleton$// COMMAND_LISTENER_SKELETON_CHANGE ---> currentSkeleton$.next// 'sheet.mutation.set-worksheet-row-auto-height' is one of COMMAND_LISTENER_SKELETON_CHANGE@@ -220,17 +220,15 @@ export class SheetSelectionRenderService extends BaseSelectionRenderService implif (prevSheetId !== skeleton.worksheet.getSheetId()) {// If there is no initial selection, add one by default in the top left corner.- const firstSelection = this._workbookSelections.getCurrentLastSelection();- if (!firstSelection) {- // WARNING: SetSelectionsOperation with type=null would clear all exists selections- // SetSelectionsOperation ---> selectionManager@setSelections ---> moveEnd$ ---> selectionRenderService@_reset- // TODO @lumixraku why use such weird a way to clear existing selection? subscribe to currentSkeleton$ is much better?- this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {- unitId,- subUnitId: sheetId,- selections: [getTopLeftSelection(skeleton)],- } as ISetSelectionsOperationParams);- }+ const selections = this._workbookSelections.getCurrentSelections();+ // WARNING: SetSelectionsOperation with type=null would clear all exists selections+ // SetSelectionsOperation ---> selectionManager@setSelections ---> moveEnd$ ---> selectionRenderService@_reset+ // TODO @lumixraku why use such weird a way to clear existing selection? subscribe to currentSkeleton$ is much better?+ this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {+ unitId,+ subUnitId: sheetId,+ selections: selections.length !== 0 ? selections : [getTopLeftSelection(skeleton)],+ } as ISetSelectionsOperationParams);}const currentSelections = this._workbookSelections.getCurrentSelections();diff --git a/packages/sheets/src/commands/operations/selection.operation.ts b/packages/sheets/src/commands/operations/selection.operation.tsindex a5f0963a4c..d6500aaecc 100644--- a/packages/sheets/src/commands/operations/selection.operation.ts+++ b/packages/sheets/src/commands/operations/selection.operation.ts@@ -36,7 +36,10 @@ export const SetSelectionsOperation: IOperation<ISetSelectionsOperationParams> =const { selections, type, unitId, subUnitId } = params;const selectionManagerService = getSelectionsService(accessor);- selectionManagerService.setSelections(unitId, subUnitId, selections, type);+ // must be a new selectionData+ // this._ensureWorkbookSelection(unitIdOrSelections).setSelections would clear selection Data on selecitonManagerInstance.+ // see issues#2199+ selectionManagerService.setSelections(unitId, subUnitId, [...selections], type);return true;},diff --git a/packages/sheets/src/services/selections/selection-manager.service.ts b/packages/sheets/src/services/selections/selection-manager.service.tsindex ff5d1dcf7d..92794c32f4 100644--- a/packages/sheets/src/services/selections/selection-manager.service.ts+++ b/packages/sheets/src/services/selections/selection-manager.service.ts@@ -231,7 +231,7 @@ export class WorkbookSelections extends Disposable {this._emitOnEnd([]);}- addSelections(sheetId: string, selectionDatas: ISelectionWithStyle[]) {+ addSelections(sheetId: string, selectionDatas: ISelectionWithStyle[]): void {const selections = this._ensureSheetSelection(sheetId);selections.push(...selectionDatas);this._emitOnEnd(selections);@@ -244,7 +244,7 @@ export class WorkbookSelections extends Disposable {* @param selectionDatas* @param type*/- setSelections(sheetId: string, selectionDatas: ISelectionWithStyle[], type: SelectionMoveType = SelectionMoveType.MOVE_END) {+ setSelections(sheetId: string, selectionDatas: ISelectionWithStyle[], type: SelectionMoveType): void {// selectionDatas should not be same variable as this._worksheetSelections !!!// but there are some place get selection from this._worksheetSelections and set selectionDatas(2nd parameter of this function ) cause selectionDatas is always []// see univer/pull/2909