Skip to content

Commit

Permalink
fix(list-render): fix g hierarchy when add group and element move #WI…
Browse files Browse the repository at this point in the history
…K-15207 (#841)
  • Loading branch information
pubuzhixing8 authored Apr 19, 2024
1 parent 2010baa commit 33bdfa1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/slimy-jars-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@plait/core': patch
---

fix g hierarchy when add group and element move

set correctly currentIndexForFirstElement value when move operation and update operation happened on same timing
5 changes: 3 additions & 2 deletions packages/core/src/core/list-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ListRender {
const newContexts: PlaitPluginElementContext[] = [];
const newComponentRefs: ComponentRef<PlaitPluginElementComponent>[] = [];
let currentIndexForFirstElement: number | null = null;
diffResult.forEachItem((record: IterableChangeRecord<any>) => {
diffResult.forEachItem((record: IterableChangeRecord<PlaitElement>) => {
NODE_TO_INDEX.set(record.item, record.currentIndex as number);
NODE_TO_PARENT.set(record.item, childrenContext.parent);
const previousContext = record.previousIndex === null ? undefined : this.contexts[record.previousIndex];
Expand All @@ -68,7 +68,8 @@ export class ListRender {
newComponentRefs.push(componentRef);
newContexts.push(context);
}
if (record.item === this.children[0]) {
// item might has been changed, so need to compare the id
if (record.item === this.children[0] || record.item.id === this.children[0]?.id) {
currentIndexForFirstElement = record.currentIndex;
}
});
Expand Down

0 comments on commit 33bdfa1

Please sign in to comment.