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
chore: fix getActiveSheet allow null (#2728)
lumixd6304a09a234
diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.tsindex c38dc76833..e85d4da7eb 100644--- a/packages/core/src/sheets/workbook.ts+++ b/packages/core/src/sheets/workbook.ts@@ -207,7 +207,6 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVER/*** Get the active sheet.*/-getActiveSheet(): Worksheet;getActiveSheet(allowNull: true): Nullable<Worksheet>;getActiveSheet(allowNull?: true): Nullable<Worksheet> {@@ -246,7 +245,12 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVERreturn worksheet;}- setActiveSheet(worksheet: Nullable<Worksheet>): void {+ /**+ * ActiveSheet should not be null!+ * There is at least one sheet in a workbook. You can not delete all sheets in a workbook.+ * @param worksheet+ */+ setActiveSheet(worksheet: Worksheet): void {this._activeSheet$.next(worksheet);}@@ -256,10 +260,6 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVERreturn false;}- if (this._activeSheet?.getSheetId() === sheetId) {- this.setActiveSheet(null);- }-this._worksheets.delete(sheetId);this._snapshot.sheetOrder.splice(this._snapshot.sheetOrder.indexOf(sheetId), 1);delete this._snapshot.sheets[sheetId];diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.tsindex ce04c298b1..933ebeb54a 100644--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts@@ -80,6 +80,8 @@ export class SheetDrawingUpdateController extends Disposable {this._groupDrawingListener();this._focusDrawingListener();++ this._drawingAddListener();}/**diff --git a/packages/sheets-drawing-ui/src/plugin.ts b/packages/sheets-drawing-ui/src/plugin.tsindex 596fe799fb..e684e0794f 100644--- a/packages/sheets-drawing-ui/src/plugin.ts+++ b/packages/sheets-drawing-ui/src/plugin.ts@@ -75,7 +75,6 @@ export class UniverSheetsDrawingUIPlugin extends Plugin {[DrawingPopupMenuController],[SheetDrawingPrintingController],[SheetDrawingPermissionController],- [SheetsDrawingCopyPasteController],];const renderModules = [diff --git a/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts b/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.tsindex b355740872..d04887c087 100644--- a/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts+++ b/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts@@ -132,24 +132,22 @@ export class ActiveWorksheetController extends Disposable {// But how to decide which one is the previous sheet? We store the deleted sheet' index// in the `IRemoteSheetMutationParams` and use it to decide the previous sheet.- // If the selected sheet is not the deleted one, we don't have to do things.+ // If the current sheet is not the deleted one, we don't have to call _switchToNextSheet.const { unitId } = mutation.params;const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);if (!workbook) {return;}- // The deleted sheet is not the currently active sheet, we don't have to do things.+ // _switchToNextSheet is executed only when the current sheet is deleted.const activeSheet = workbook.getActiveSheet();- if (activeSheet) {- return;- }-- const previousIndex = this._previousSheetIndex;- const nextIndex = previousIndex >= 1 ? previousIndex - 1 : 0;- const nextId = findTheNextUnhiddenSheet(workbook, nextIndex);+ if (activeSheet.getSheetId() === mutation.params.subUnitId) {+ const previousIndex = this._previousSheetIndex;+ const nextIndex = previousIndex >= 1 ? previousIndex - 1 : 0;+ const nextId = findTheNextUnhiddenSheet(workbook, nextIndex);- this._switchToNextSheet(unitId, nextId);+ this._switchToNextSheet(unitId, nextId);+ }}private _adjustActiveSheetOnInsertSheet(mutation: IMutationInfo<IInsertSheetMutationParams>) {diff --git a/packages/sheets-ui/src/controllers/auto-height.controller.ts b/packages/sheets-ui/src/controllers/auto-height.controller.tsindex 3aefc637b6..69d430d58c 100644--- a/packages/sheets-ui/src/controllers/auto-height.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-height.controller.ts@@ -59,14 +59,13 @@ export class AutoHeightController extends Disposable {const unitId = workbook.getUnitId();const subUnitId = workbook.getActiveSheet()?.getSheetId();- if (!subUnitId) {+ const sheetSkeletonService = this._renderManagerService.getRenderById(unitId)!.with<SheetSkeletonManagerService>(SheetSkeletonManagerService);+ if (!subUnitId || !sheetSkeletonService.getCurrent()) {return {redos: [],undos: [],};}-- const sheetSkeletonService = this._renderManagerService.getRenderById(unitId)!.with(SheetSkeletonManagerService);const { skeleton } = sheetSkeletonService.getCurrent()!;const rowsAutoHeightInfo = skeleton.calculateAutoHeightInRange(ranges);