diff --git a/packages/editor/src/services/editor.ts b/packages/editor/src/services/editor.ts index 4ac8d8b7..6d1da4de 100644 --- a/packages/editor/src/services/editor.ts +++ b/packages/editor/src/services/editor.ts @@ -523,15 +523,15 @@ class Editor extends BaseService { * @param config 组件节点配置 * @returns 当前组件节点配置 */ - public async alignCenter(config: MNode): Promise { + public async alignCenter(config: MNode): Promise { const parent = this.get('parent'); - const node = this.get('node'); - const layout = await this.getLayout(toRaw(parent), toRaw(node)); + const node = cloneDeep(toRaw(config)); + const layout = await this.getLayout(toRaw(parent), node); if (layout === Layout.RELATIVE) { - return; + return config; } - if (!node.style) return; + if (!node.style) return config; const stage = this.get('stage'); const doc = stage?.renderer.contentWindow?.document; @@ -546,15 +546,14 @@ class Editor extends BaseService { node.style.left = (parent.style.width - node.style.width) / 2; } - await this.update(node); + const newNode = await this.update(node); + this.get('stage')?.update({ - config: cloneDeep(toRaw(node)), + config: cloneDeep(toRaw(newNode)), root: cloneDeep(this.get('root')), }); - this.addModifiedNodeId(config.id); - this.pushHistoryState(); - return config; + return newNode; } /**