@@ -32,11 +32,13 @@ export class ListRender {
3232 public initialize ( children : Descendant [ ] , parent : Ancestor , childrenContext : SlateChildrenContext ) {
3333 this . initialized = true ;
3434 this . children = children ;
35+ const isRoot = parent === this . viewContext . editor ;
36+ const firstIndex = isRoot ? this . viewContext . editor . children . indexOf ( children [ 0 ] ) : 0 ;
3537 const parentPath = AngularEditor . findPath ( this . viewContext . editor , parent ) ;
36- children . forEach ( ( descendant , index ) => {
37- NODE_TO_INDEX . set ( descendant , index ) ;
38+ children . forEach ( ( descendant , _index ) => {
39+ NODE_TO_INDEX . set ( descendant , firstIndex + _index ) ;
3840 NODE_TO_PARENT . set ( descendant , parent ) ;
39- const context = getContext ( index , descendant , parentPath , childrenContext , this . viewContext ) ;
41+ const context = getContext ( firstIndex + _index , descendant , parentPath , childrenContext , this . viewContext ) ;
4042 const viewType = getViewType ( descendant , parent , this . viewContext ) ;
4143 const view = createEmbeddedViewOrComponentOrFlavour ( viewType , context , this . viewContext , this . viewContainerRef ) ;
4244 const blockCard = createBlockCard ( descendant , view , this . viewContext ) ;
@@ -65,16 +67,19 @@ export class ListRender {
6567 const outletParent = this . getOutletParent ( ) ;
6668 const diffResult = this . differ . diff ( children ) ;
6769 const parentPath = AngularEditor . findPath ( this . viewContext . editor , parent ) ;
70+ const isRoot = parent === this . viewContext . editor ;
71+ const firstIndex = isRoot ? this . viewContext . editor . children . indexOf ( children [ 0 ] ) : 0 ;
6872 if ( diffResult ) {
6973 let firstRootNode = getRootNodes ( this . views [ 0 ] , this . blockCards [ 0 ] ) [ 0 ] ;
7074 const newContexts = [ ] ;
7175 const newViewTypes = [ ] ;
7276 const newViews = [ ] ;
7377 const newBlockCards : ( BlockCardRef | null ) [ ] = [ ] ;
7478 diffResult . forEachItem ( record => {
75- NODE_TO_INDEX . set ( record . item , record . currentIndex ) ;
79+ const currentIndex = firstIndex + record . currentIndex ;
80+ NODE_TO_INDEX . set ( record . item , currentIndex ) ;
7681 NODE_TO_PARENT . set ( record . item , parent ) ;
77- let context = getContext ( record . currentIndex , record . item , parentPath , childrenContext , this . viewContext ) ;
82+ let context = getContext ( currentIndex , record . item , parentPath , childrenContext , this . viewContext ) ;
7883 const viewType = getViewType ( record . item , parent , this . viewContext ) ;
7984 newViewTypes . push ( viewType ) ;
8085 let view : EmbeddedViewRef < any > | ComponentRef < any > | FlavourRef ;
@@ -154,15 +159,15 @@ export class ListRender {
154159 }
155160 } else {
156161 const newContexts = [ ] ;
157- this . children . forEach ( ( child , index ) => {
158- NODE_TO_INDEX . set ( child , index ) ;
162+ this . children . forEach ( ( child , _index ) => {
163+ NODE_TO_INDEX . set ( child , firstIndex + _index ) ;
159164 NODE_TO_PARENT . set ( child , parent ) ;
160- let context = getContext ( index , child , parentPath , childrenContext , this . viewContext ) ;
161- const previousContext = this . contexts [ index ] ;
165+ let context = getContext ( firstIndex + _index , child , parentPath , childrenContext , this . viewContext ) ;
166+ const previousContext = this . contexts [ _index ] ;
162167 if ( memoizedContext ( this . viewContext , child , previousContext as any , context as any ) ) {
163168 context = previousContext ;
164169 } else {
165- updateContext ( this . views [ index ] , context , this . viewContext ) ;
170+ updateContext ( this . views [ _index ] , context , this . viewContext ) ;
166171 }
167172 newContexts . push ( context ) ;
168173 } ) ;
0 commit comments