@@ -17,7 +17,7 @@ import {
1717 Timespan ,
1818 compare ,
1919} from '../../json-crdt-patch' ;
20- import { BinNode , ObjNode , StrNode , ValNode , VecNode } from '../nodes' ;
20+ import { ArrNode , BinNode , ObjNode , StrNode , ValNode , VecNode } from '../nodes' ;
2121import type { FanOutUnsubscribe } from 'thingies/lib/fanout' ;
2222import type { Printable } from 'tree-dump/lib/types' ;
2323import type { JsonNode } from '../nodes/types' ;
@@ -195,7 +195,7 @@ export class Log<N extends JsonNode = JsonNode<any>> implements Printable {
195195 continue ;
196196 }
197197 const model = getModel ( ) ;
198- // TODO: Do not overwrite already deleted values? Or needed for concurrency?
198+ // TODO: Do not overwrite already deleted values? Or needed for concurrency? Orphaned nodes.
199199 if ( op instanceof InsValOp ) {
200200 const val = model . index . get ( op . obj ) ;
201201 if ( val instanceof ValNode ) {
@@ -247,6 +247,28 @@ export class Log<N extends JsonNode = JsonNode<any>> implements Printable {
247247 }
248248 const blob = listToUint8 ( buffers ) ;
249249 builder . insBin ( op . obj , after , blob ) ;
250+ } else if ( rga instanceof ArrNode ) {
251+ const copies : ITimestampStruct [ ] = [ ] ;
252+ for ( const span of op . what ) {
253+ const ids2 = rga . spanView ( span ) ;
254+ for ( const ids of ids2 ) {
255+ for ( const id of ids ) {
256+ const node = model . index . get ( id ) ;
257+ if ( node ) {
258+ const schema = toSchema ( node ) ;
259+ const newId = schema . build ( builder ) ;
260+ copies . push ( newId ) ;
261+ }
262+ }
263+ }
264+ }
265+ let after = op . obj ;
266+ const firstDelSpan = op . what [ 0 ] ;
267+ if ( firstDelSpan ) {
268+ const after2 = rga . prevId ( firstDelSpan ) ;
269+ if ( after2 ) after = after2 ;
270+ }
271+ builder . insArr ( op . obj , after , copies ) ;
250272 }
251273 }
252274 }
0 commit comments