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(sheets-formula-ui): handle undefined unitId in formula selection (#5627)

WEI ZHANG65a87a7be651
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-formula-selection.ts b/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-formula-selection.ts
index d874571c11..6234fa1bdf 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-formula-selection.ts
+++ b/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-formula-selection.ts
@@ -114,7 +114,8 @@ export function useFormulaSelecting(opts: { editorId: string; isFocus: boolean;
}
const { sheetName, unitId } = focusingNode.range;
- if (unitId !== univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET)?.getUnitId()) {
+ const currentUnitId = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET)?.getUnitId();
+ if (unitId && unitId !== currentUnitId) {
setIsSelecting(FormulaSelectingType.EDIT_OTHER_WORKBOOK_REFERENCE);
} else if (
(!sheetName && currentSheet.getSheetId() === sourceSheet?.getSheetId()) ||