Skip to content

Commit

Permalink
fix(editor): 没有页面时,添加页面出错
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen authored and jia000 committed Aug 31, 2022
1 parent 13ef262 commit e67cbce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/editor/src/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,15 @@ export default defineComponent({
emits: ['props-panel-mounted', 'update:modelValue'],
setup(props, { emit }) {
editorService.on('root-change', () => {
const node = editorService.get<MNode | null>('node') || props.defaultSelected;
node && editorService.select(node);
editorService.on('root-change', (value) => {
const node = editorService.get<MNode | null>('node');
const nodeId = node?.id || props.defaultSelected;
if (nodeId && node !== value) {
editorService.select(nodeId);
} else {
editorService.set('nodes', [value]);
}
emit('update:modelValue', toRaw(editorService.get('root')));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/services/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class Editor extends BaseService {
await this.select(root.items[0]);
stage?.select(root.items[0].id);
} else {
this.set('node', null);
this.set('nodes', [root]);
this.set('parent', null);
this.set('page', null);
this.set('stage', null);
Expand Down

0 comments on commit e67cbce

Please sign in to comment.