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: optimize the API so that the statistics bar is also updated when setting the selection range (#6533)
wpxp1234564b3baeb83a8c
diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.tsindex 0bb6bc9c07..ae9013ef59 100644--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts@@ -16,7 +16,7 @@import type { CellValue, ICellData, ICommandInfo, IObjectMatrixPrimitiveType, IRange, ISelectionCell, IStyleData, Nullable, Styles, Workbook, Worksheet } from '@univerjs/core';import type { ArrayValueObject, ISheetData } from '@univerjs/engine-formula';-import type { ISelectionWithStyle } from '@univerjs/sheets';+import type { ISelectionWithStyle, ISetRangeValuesMutationParams } from '@univerjs/sheets';import type { IStatusBarServiceStatus } from '../services/status-bar.service';import {CellValueType,@@ -207,12 +207,43 @@ export class StatusBarController extends Disposable {));+ this.disposeWithMe(+ toDisposable(+ this._selectionManagerService.selectionSet$.subscribe((selections) => {+ if (selections) {+ _statisticsHandler(selections);+ }+ })+ )+ );+this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => {if (command.id === SetRangeValuesMutation.id) {const selections = this._selectionManagerService.getCurrentSelections();- if (selections) {- _statisticsHandler(selections as ISelectionWithStyle[]);+ const { cellValue } = command.params as ISetRangeValuesMutationParams;++ if (selections && selections.length > 0 && cellValue) {+ const cellValueMatrix = new ObjectMatrix(cellValue);++ // Do not update statistics if the changed cells are outside the current selection+ let valueInSelection = false;++ cellValueMatrix.forValue((row, col) => {+ if (+ selections.some((selection) => {+ const range = selection.range;+ return row >= range.startRow && row <= range.endRow && col >= range.startColumn && col <= range.endColumn;+ })+ ) {+ valueInSelection = true;+ return false; // Stop iteration+ }+ });++ if (valueInSelection) {+ _statisticsHandler(selections as ISelectionWithStyle[]);+ }}}})