fix(editor): 上移一层通知runtime更新参数出错

fix #282
This commit is contained in:
roymondchen 2022-08-24 10:35:01 +08:00 committed by jia000
parent 5529bbc6e1
commit 9b9c9db683
3 changed files with 9 additions and 3 deletions

View File

@ -620,7 +620,7 @@ class Editor extends BaseService {
*/ */
public async moveLayer(offset: number | LayerOffset): Promise<void> { public async moveLayer(offset: number | LayerOffset): Promise<void> {
const parent = this.get<MContainer>('parent'); const parent = this.get<MContainer>('parent');
const node = this.get('node'); const node = this.get<MNode>('node');
const brothers: MNode[] = parent?.items || []; const brothers: MNode[] = parent?.items || [];
const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`); const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
@ -632,11 +632,15 @@ class Editor extends BaseService {
brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]); brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
} }
const grandparent = this.getParentById(parent.id);
this.get<StageCore | null>('stage')?.update({ this.get<StageCore | null>('stage')?.update({
config: cloneDeep(toRaw(parent)), config: cloneDeep(toRaw(parent)),
parentId: parent.id, parentId: grandparent?.id,
root: cloneDeep(this.get<MApp>('root')), root: cloneDeep(this.get<MApp>('root')),
}); });
this.addModifiedNodeId(parent.id);
this.pushHistoryState();
} }
/** /**

View File

@ -23,6 +23,7 @@ import type { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
import { NodeType } from '@tmagic/schema'; import { NodeType } from '@tmagic/schema';
import editorService from '@editor/services/editor'; import editorService from '@editor/services/editor';
import historyService from '@editor/services/history';
import storageService from '@editor/services/storage'; import storageService from '@editor/services/storage';
import { COPY_STORAGE_KEY } from '@editor/utils'; import { COPY_STORAGE_KEY } from '@editor/utils';
@ -414,6 +415,7 @@ describe('undo redo', () => {
beforeAll(() => editorService.set('root', cloneDeep(root))); beforeAll(() => editorService.set('root', cloneDeep(root)));
test('正常', async () => { test('正常', async () => {
historyService.reset();
// 设置当前编辑的组件 // 设置当前编辑的组件
await editorService.select(NodeId.NODE_ID); await editorService.select(NodeId.NODE_ID);
const node = editorService.get('node'); const node = editorService.get('node');

View File

@ -79,7 +79,7 @@ describe('isFixed', () => {
type: 'text', type: 'text',
id: 1, id: 1,
style: { style: {
absulote: 'absulote', position: 'absolute',
}, },
}), }),
).toBeFalsy(); ).toBeFalsy();