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(group): add sheet transfrom for drawing cmd (#6549)

VicKuncc70157965f8
diff --git a/packages/engine-render/src/base-object.ts b/packages/engine-render/src/base-object.ts
index 3e723a2222..fbf3ccecc0 100644
--- a/packages/engine-render/src/base-object.ts
+++ b/packages/engine-render/src/base-object.ts
@@ -253,11 +253,15 @@ export abstract class BaseObject extends Disposable {
get ancestorGroup() {
let group: Nullable<BaseObject> = null;
let parent = this.getParent();
- while (parent != null) {
+ while (parent != null && parent) {
if (parent.classType === RENDER_CLASS_TYPE.GROUP) {
group = parent;
}
- parent = parent.getParent();
+ if (parent.classType === RENDER_CLASS_TYPE.GROUP) {
+ parent = parent.getParent();
+ } else {
+ parent = null;
+ }
}
return group;
}
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.ts
index d8b766d146..24ad44adaa 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
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { IAccessor, IRange, Nullable, Workbook } from '@univerjs/core';
+import type { IAccessor, IDrawingParam, IRange, Nullable, Workbook } from '@univerjs/core';
import type { IImageData, IImageIoServiceParam } from '@univerjs/drawing';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import type { ISheetLocationBase, WorkbookSelectionModel } from '@univerjs/sheets';
@@ -601,15 +601,75 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
}));
}
+ private _getSheetTransformByParam(param: IDrawingParam): Nullable<ISheetDrawingPosition> {
+ const { unitId, subUnitId, drawingId, transform } = param;
+ if (transform == null) {
+ return null;
+ }
+ const sheetDrawing = this._sheetDrawingService.getDrawingByParam({ unitId, subUnitId, drawingId });
+
+ if (sheetDrawing == null || sheetDrawing.unitId !== this._context.unitId) {
+ return null;
+ }
+ const sheetTransform = transformToDrawingPosition({ ...sheetDrawing.transform, ...transform }, this._selectionRenderService);
+
+ if (sheetTransform == null) {
+ return null;
+ }
+ return sheetTransform;
+ }
+
private _groupDrawingListener() {
this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe((params) => {
- this._commandService.executeCommand(GroupSheetDrawingCommand.id, params);
- const { unitId, subUnitId, drawingId } = params[0].parent;
- this._commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, [{ unitId, subUnitId, drawingId }]);
+ const grpParams = [];
+ for (const param of params) {
+ const sheetTransform = this._getSheetTransformByParam(param.parent);
+
+ const children = [];
+ for (const child of param.children) {
+ const childSheetTransform = this._getSheetTransformByParam(child);
+ if (childSheetTransform != null) {
+ children.push({
+ ...child,
+ sheetTransform: childSheetTransform,
+ });
+ }
+ }
+
+ const grpParam = {
+ parent: { ...param.parent, sheetTransform },
+ children,
+
+ };
+ grpParams.push(grpParam);
+ }
+ if (grpParams.length > 0) {
+ this._commandService.executeCommand(GroupSheetDrawingCommand.id, grpParams);
+ const { unitId, subUnitId, drawingId } = params[0].parent;
+ this._commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, [{ unitId, subUnitId, drawingId }]);
+ }
}));
this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((params) => {
- this._commandService.executeCommand(UngroupSheetDrawingCommand.id, params);
+ const unGroupParams = [];
+ for (const param of params) {
+ const { children } = param;
+ const childParams = [];
+ for (const child of children) {
+ const childSheetTransform = this._getSheetTransformByParam(child);
+ if (childSheetTransform != null) {
+ childParams.push({
+ ...child,
+ sheetTransform: childSheetTransform,
+ });
+ }
+ }
+ unGroupParams.push({
+ ...param,
+ children: childParams,
+ });
+ }
+ this._commandService.executeCommand(UngroupSheetDrawingCommand.id, unGroupParams);
}));
}
diff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
index f4b8c1b392..4b6c94cac6 100644
--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
@@ -19,7 +19,7 @@ import type { BaseObject, IBoundRectNoAngle, IRender, IShapeProps, Shape, Spread
import type { ISetWorksheetRowAutoHeightMutationParams, ISheetLocationBase } from '@univerjs/sheets';
import type { IPopup } from '@univerjs/ui';
import { Disposable, DisposableCollection, fromEventSubject, ICommandService, Inject, IUniverInstanceService, toDisposable, UniverInstanceType } from '@univerjs/core';
-import { IRenderManagerService } from '@univerjs/engine-render';
+import { IRenderManagerService, RENDER_CLASS_TYPE } from '@univerjs/engine-render';
import { COMMAND_LISTENER_SKELETON_CHANGE, IRefSelectionsService, RefRangeService, SetFrozenMutation, SetSelectionsOperation, SetWorksheetRowAutoHeightMutation, SheetsSelectionsService } from '@univerjs/sheets';
import { ICanvasPopupService } from '@univerjs/ui';
import { BehaviorSubject, map, throttleTime } from 'rxjs';
@@ -287,7 +287,10 @@ export class SheetCanvasPopManagerService extends Disposable {
let offsetX = 0;
let offsetY = 0;
- const drawingType = (targetObject as Shape<IShapeProps & { drawingType: DrawingTypeEnum }>).getPropByKey('drawingType');
+ let drawingType;
+ if (targetObject.classType === RENDER_CLASS_TYPE.SHAPE) {
+ drawingType = (targetObject as Shape<IShapeProps & { drawingType: DrawingTypeEnum }>).getPropByKey('drawingType');
+ }
if (drawingType !== undefined && this._popupMenuOffsetMap.has(drawingType)) {
const offset = this._popupMenuOffsetMap.get(drawingType)!;
offsetX = offset.offsetX;