Skip to content

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.

fix: array status bar (#6117)

Dushusir3ff8ac0b7e70
diff --git a/e2e/visual-comparison/sheets/sheets-scroll.spec.ts b/e2e/visual-comparison/sheets/sheets-scroll.spec.ts
index a7373ca2d0..ec4fe85e82 100644
--- a/e2e/visual-comparison/sheets/sheets-scroll.spec.ts
+++ b/e2e/visual-comparison/sheets/sheets-scroll.spec.ts
@@ -101,3 +101,119 @@ test('rendering after scrolling by API', async () => {
const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();
await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixelRatio: 0.005 });
});
+
+test('status bar count with array formula selection', async () => {
+ const browser = await chromium.launch({
+ headless: isCI, // Set to false to see the browser window in local
+ });
+ const context = await browser.newContext({
+ viewport: { width: 1280, height: 1280 },
+ deviceScaleFactor: 2, // Set your desired DPR
+ });
+ const page = await context.newPage();
+ await page.goto('http://localhost:3000/sheets/');
+ await page.waitForTimeout(2000);
+
+ // Load the snapshot with array formula
+ await page.evaluate(() => {
+ const snapshot = {
+ id: 'workbook-status-bar-array-formula',
+ sheetOrder: [
+ 'sheet-01',
+ ],
+ name: 'New Sheet',
+ appVersion: '1',
+ locale: 'enUS',
+ styles: {},
+ sheets: {
+ 'sheet-01': {
+ id: 'sheet-01',
+ name: 'Sheet1',
+ rowCount: 1000,
+ columnCount: 20,
+ freeze: {
+ xSplit: 0,
+ ySplit: 0,
+ startRow: -1,
+ startColumn: -1,
+ },
+ hidden: 0,
+ rowData: {},
+ tabColor: '',
+ mergeData: [],
+ rowHeader: {
+ width: 46,
+ hidden: 0,
+ },
+ scrollTop: 200,
+ zoomRatio: 1,
+ columnData: {},
+ scrollLeft: 100,
+ rightToLeft: 0,
+ columnHeader: {
+ height: 20,
+ hidden: 0,
+ },
+ showGridlines: 1,
+ defaultRowHeight: 24,
+ defaultColumnWidth: 88,
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ t: 2,
+ },
+ 1: {
+ v: 1,
+ t: 2,
+ },
+ 3: {
+ f: '=A1:B2',
+ t: 2,
+ },
+ 5: {
+ v: 2,
+ t: 2,
+ },
+ },
+ 1: {
+ 0: {
+ v: 1,
+ t: 2,
+ },
+ 1: {
+ v: 1,
+ t: 2,
+ },
+ 5: {
+ v: 2,
+ t: 2,
+ },
+ },
+ },
+ },
+ },
+ };
+ window.univerAPI.dispose();
+ setTimeout(() => {
+ window.univerAPI.createUniverSheet(snapshot);
+ }, 500);
+ });
+ await page.waitForTimeout(1000);
+
+ // Select the array formula range D1:E2
+ await page.evaluate(() => {
+ const activeRange = window.univerAPI.getActiveWorkbook().getActiveSheet().getRange({ startRow: 0, startColumn: 3, endRow: 1, endColumn: 5 });
+ activeRange.activate();
+
+ // set new value to trigger status bar update
+ const range = window.univerAPI.getActiveWorkbook().getActiveSheet().getRange({ startRow: 1, startColumn: 5, endRow: 1, endColumn: 5 });
+ range.setValue(3);
+ });
+ await page.waitForTimeout(1000);
+
+ // Take screenshot including status bar
+ const filename = generateSnapshotName('arrayFormulaStatusBarCount');
+ const screenshot = await page.screenshot({ fullPage: false });
+ await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixelRatio: 0.005 });
+});
diff --git a/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/arrayFormulaStatusBarCount-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/arrayFormulaStatusBarCount-ci-chromium-linux.png
new file mode 100644
index 0000000000..723562af11
Binary files /dev/null and b/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/arrayFormulaStatusBarCount-ci-chromium-linux.png differ
diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.ts
index 37b69c4df2..0bb6bc9c07 100644
--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts
+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { CellValue, ICellData, ICommandInfo, IRange, ISelectionCell, IStyleData, Nullable, Styles, Workbook, Worksheet } from '@univerjs/core';
+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 { IStatusBarServiceStatus } from '../services/status-bar.service';
@@ -37,6 +37,7 @@ import {
} from '@univerjs/core';
import {
+ FormulaDataModel,
FUNCTION_NAMES_MATH,
FUNCTION_NAMES_STATISTICAL,
} from '@univerjs/engine-formula';
@@ -157,7 +158,8 @@ export class StatusBarController extends Disposable {
@Inject(SheetsSelectionsService) private readonly _selectionManagerService: SheetsSelectionsService,
@IStatusBarService private readonly _statusBarService: IStatusBarService,
@ICommandService private readonly _commandService: ICommandService,
- @Inject(INumfmtService) private _numfmtService: INumfmtService
+ @Inject(INumfmtService) private _numfmtService: INumfmtService,
+ @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel
) {
super();
@@ -255,6 +257,24 @@ export class StatusBarController extends Disposable {
};
}
+ private _getCellValue(row: number, col: number, sheet: Worksheet, sheetArrayFormulaCellData?: IObjectMatrixPrimitiveType<Nullable<ICellData>>): Nullable<ICellData> {
+ const rawCell = sheet.getCellRaw(row, col);
+
+ // Check array formula cell data if raw cell has no value
+ const arrayCell = sheetArrayFormulaCellData?.[row]?.[col];
+
+ if (arrayCell) {
+ // Merge only the necessary properties (t, v, s) to avoid full object spread and improve performance
+ return {
+ t: arrayCell.t ?? rawCell?.t,
+ v: arrayCell.v ?? rawCell?.v,
+ s: arrayCell.s ?? rawCell?.s,
+ };
+ }
+
+ return rawCell;
+ }
+
// eslint-disable-next-line max-lines-per-function
private _calculateSelection(selections: IRange[], primary: Nullable<ISelectionCell>) {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
@@ -312,11 +332,15 @@ export class StatusBarController extends Disposable {
const styles = workbook.getStyles();
const patternInfoRecord: Record<string, any> = {};
+ // Cache arrayFormulaCellData outside the loop to avoid repeated calls
+ const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
+ const sheetArrayFormulaCellData = arrayFormulaCellData?.[unitId]?.[sheetId];
+
for (const range of noDuplicate) {
const { startRow, startColumn, endColumn, endRow } = this.getRangeStartEndInfo(range, sheet);
for (let r = startRow; r <= endRow; r++) {
for (let c = startColumn; c <= endColumn; c++) {
- const value = sheet.getCellRaw(r, c);
+ const value = this._getCellValue(r, c, sheet, sheetArrayFormulaCellData);
calculateValueSet.add(value, styles, patternInfoRecord);
}
}