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(sheet): formula ref update and overflow error (#906)

Univeref4a669cf350
diff --git a/packages/engine-render/src/components/sheets/spreadsheet.ts b/packages/engine-render/src/components/sheets/spreadsheet.ts
index b926ac6d57..029418a045 100644
--- a/packages/engine-render/src/components/sheets/spreadsheet.ts
+++ b/packages/engine-render/src/components/sheets/spreadsheet.ts
@@ -114,9 +114,6 @@ export class Spreadsheet extends SheetComponent {
const { a: scaleX = 1, d: scaleY = 1 } = ctx.getTransform();
- // insert overflow cache
- this._calculateOverflow();
-
const diffRanges = this._refreshIncrementalState
? bounds?.diffBounds.map((bound) => spreadsheetSkeleton.getRowColumnSegmentByViewBound(bound))
: undefined;
@@ -622,6 +619,9 @@ export class Spreadsheet extends SheetComponent {
return;
}
+ // insert overflow cache
+ this._calculateOverflow();
+
const { rowColumnSegment, dataMergeCache, overflowCache, stylesCache, showGridlines } = spreadsheetSkeleton;
const { border, backgroundPositions } = stylesCache;
const { startRow, endRow, startColumn, endColumn } = rowColumnSegment;
diff --git a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts
index 4da6709a30..a61993f4fa 100644
--- a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts
@@ -403,9 +403,13 @@ export class StartEditController extends Disposable {
documentComponent.resize(editorWidth, editorHeight);
- // resize canvas
-
- engine.resizeBySize(editorWidth, physicHeight);
+ /**
+ * resize canvas
+ * When modifying the selection area for a formula, it is necessary to add a setTimeout to ensure successful updating.
+ */
+ setTimeout(() => {
+ engine.resizeBySize(editorWidth, physicHeight);
+ }, 0);
// Update cell editor container position and size.
this._cellEditorManagerService.setState({
diff --git a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
index 585aff3035..9c67b42249 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape-extension.ts
@@ -296,7 +296,7 @@ export class SelectionShapeExtension {
});
});
- this._upObserver = scene.onPointerUpObserver.add((upEvt: IPointerEvent | IMouseEvent) => {
+ this._upObserver = scene.onPointerUpObserver.add(() => {
this._helperSelection?.dispose();
const scene = this._scene;
scene.resetCursor();
@@ -340,11 +340,11 @@ export class SelectionShapeExtension {
bottomCenterWidget,
bottomRightWidget,
].forEach((control, index) => {
- control.onPointerEnterObserver.add((evt: IMouseEvent | IPointerEvent) => {
+ control.onPointerEnterObserver.add(() => {
control.setCursor(cursors[index]);
});
- control.onPointerLeaveObserver.add((evt: IMouseEvent | IPointerEvent) => {
+ control.onPointerLeaveObserver.add(() => {
control.resetCursor();
});
@@ -373,9 +373,9 @@ export class SelectionShapeExtension {
const { rowHeaderWidth, columnHeaderHeight } = this._skeleton;
- const maxRow = this._skeleton.getRowCount() - 1;
+ // const maxRow = this._skeleton.getRowCount() - 1;
- const maxColumn = this._skeleton.getColumnCount() - 1;
+ // const maxColumn = this._skeleton.getColumnCount() - 1;
let startRow = this._relativeSelectionPositionRow;
@@ -515,7 +515,7 @@ export class SelectionShapeExtension {
});
});
- this._upObserver = scene.onPointerUpObserver.add((upEvt: IPointerEvent | IMouseEvent) => {
+ this._upObserver = scene.onPointerUpObserver.add(() => {
const scene = this._scene;
scene.resetCursor();
this._clearObserverEvent();
@@ -528,11 +528,11 @@ export class SelectionShapeExtension {
private _initialFill() {
const { fillControl } = this._control;
- fillControl.onPointerEnterObserver.add((evt: IMouseEvent | IPointerEvent) => {
+ fillControl.onPointerEnterObserver.add(() => {
fillControl.setCursor(CURSOR_TYPE.CROSSHAIR);
});
- fillControl.onPointerLeaveObserver.add((evt: IMouseEvent | IPointerEvent) => {
+ fillControl.onPointerLeaveObserver.add(() => {
fillControl.resetCursor();
});
@@ -575,7 +575,7 @@ export class SelectionShapeExtension {
let isRowDropping = true;
if ((column < startColumn || column > endColumn) && row >= startRow && row <= endRow) {
- const rulerValue = this._FillRuler(
+ const rulerValue = this._fillRuler(
column,
startColumn,
endColumn,
@@ -591,7 +591,7 @@ export class SelectionShapeExtension {
isRowDropping = false;
} else if ((row < startRow || row > endRow) && column >= startColumn && column <= endColumn) {
- const rulerValue = this._FillRuler(row, startRow, endRow, this._relativeSelectionRowLength, maxRow);
+ const rulerValue = this._fillRuler(row, startRow, endRow, this._relativeSelectionRowLength, maxRow);
startRow = rulerValue.startRowOrColumn;
@@ -602,7 +602,7 @@ export class SelectionShapeExtension {
Math.abs(this._startOffsetX - moveRelativeCoords.x - scrollXY.x) / 2 >
Math.abs(this._startOffsetY - moveRelativeCoords.y - scrollXY.y)
) {
- const rulerValue = this._FillRuler(
+ const rulerValue = this._fillRuler(
column,
startColumn,
endColumn,
@@ -618,7 +618,7 @@ export class SelectionShapeExtension {
isRowDropping = false;
} else {
- const rulerValue = this._FillRuler(row, startRow, endRow, this._relativeSelectionRowLength, maxRow);
+ const rulerValue = this._fillRuler(row, startRow, endRow, this._relativeSelectionRowLength, maxRow);
startRow = rulerValue.startRowOrColumn;
@@ -767,7 +767,7 @@ export class SelectionShapeExtension {
});
});
- this._upObserver = scene.onPointerUpObserver.add((upEvt: IPointerEvent | IMouseEvent) => {
+ this._upObserver = scene.onPointerUpObserver.add(() => {
this._helperSelection?.dispose();
const scene = this._scene;
scene.resetCursor();
@@ -863,7 +863,7 @@ export class SelectionShapeExtension {
}
}
- private _FillRuler(
+ private _fillRuler(
rowOrColumn: number,
startRowOrColumn: number,
endRowOrColumn: number,