@@ -219,53 +219,69 @@ impl MovableListHandler {
219219 ) -> LoroResult < ( ) > {
220220 for v in values. iter ( ) {
221221 match v {
222+ ValueOrHandler :: Value ( LoroValue :: Container ( old_id) ) => {
223+ self . apply_insertion ( attr, context, old_id. clone ( ) ) ?;
224+ }
225+ ValueOrHandler :: Handler ( handler) => {
226+ let old_id = handler. id ( ) ;
227+ self . apply_insertion ( attr, context, old_id) ?;
228+ }
222229 ValueOrHandler :: Value ( value) => {
223230 self . insert ( * context. index , value. clone ( ) ) ?;
224231 Self :: update_positions_on_insert ( context. to_delete , * context. index , 1 ) ;
225232 * context. index += 1 ;
226233 * context. index_shift += 1 ;
227234 }
228- ValueOrHandler :: Handler ( handler) => {
229- let mut old_id = handler. id ( ) ;
230- if !context. to_delete . contains_key ( & old_id) {
231- while let Some ( new_id) = context. container_remap . get ( & old_id) {
232- old_id = new_id. clone ( ) ;
233- if context. to_delete . contains_key ( & old_id) {
234- break ;
235- }
236- }
237- }
235+ }
236+ }
238237
239- if let Some ( old_index) = context. to_delete . remove ( & old_id) {
240- if old_index > * context. index {
241- ensure_cov:: notify_cov ( "loro_internal::handler::movable_list_apply_delta::process_replacements::mov_0" ) ;
242- self . mov ( old_index, * context. index ) ?;
243- context. next_deleted . push ( Reverse ( old_index) ) ;
244- * context. index += 1 ;
245- * context. index_shift += 1 ;
246- } else {
247- ensure_cov:: notify_cov ( "loro_internal::handler::movable_list_apply_delta::process_replacements::mov_1" ) ;
248- self . mov ( old_index, * context. index - 1 ) ?;
249- }
250- context. deleted_indices . push ( old_index) ;
251- Self :: update_positions_on_delete ( context. to_delete , old_index) ;
252- Self :: update_positions_on_insert ( context. to_delete , * context. index , 1 ) ;
253- } else if !attr. from_move {
254- // Insert a new container if not moved.
255- let new_handler = self . insert_container (
256- * context. index ,
257- Handler :: new_unattached ( old_id. container_type ( ) ) ,
258- ) ?;
259- let new_id = new_handler. id ( ) ;
260- context. container_remap . insert ( old_id, new_id) ;
261- Self :: update_positions_on_insert ( context. to_delete , * context. index , 1 ) ;
262- * context. index += 1 ;
263- * context. index_shift += 1 ;
264- }
238+ Ok ( ( ) )
239+ }
240+
241+ fn apply_insertion (
242+ & self ,
243+ attr : & crate :: event:: ListDeltaMeta ,
244+ context : & mut ReplacementContext < ' _ > ,
245+ mut old_id : ContainerID ,
246+ ) -> Result < ( ) , LoroError > {
247+ if !context. to_delete . contains_key ( & old_id) {
248+ while let Some ( new_id) = context. container_remap . get ( & old_id) {
249+ old_id = new_id. clone ( ) ;
250+ if context. to_delete . contains_key ( & old_id) {
251+ break ;
265252 }
266253 }
267254 }
268-
255+ if let Some ( old_index) = context. to_delete . remove ( & old_id) {
256+ if old_index > * context. index {
257+ ensure_cov:: notify_cov (
258+ "loro_internal::handler::movable_list_apply_delta::process_replacements::mov_0" ,
259+ ) ;
260+ self . mov ( old_index, * context. index ) ?;
261+ context. next_deleted . push ( Reverse ( old_index) ) ;
262+ * context. index += 1 ;
263+ * context. index_shift += 1 ;
264+ } else {
265+ ensure_cov:: notify_cov (
266+ "loro_internal::handler::movable_list_apply_delta::process_replacements::mov_1" ,
267+ ) ;
268+ self . mov ( old_index, * context. index - 1 ) ?;
269+ }
270+ context. deleted_indices . push ( old_index) ;
271+ Self :: update_positions_on_delete ( context. to_delete , old_index) ;
272+ Self :: update_positions_on_insert ( context. to_delete , * context. index , 1 ) ;
273+ } else if !attr. from_move {
274+ // Insert a new container if not moved.
275+ let new_handler = self . insert_container (
276+ * context. index ,
277+ Handler :: new_unattached ( old_id. container_type ( ) ) ,
278+ ) ?;
279+ let new_id = new_handler. id ( ) ;
280+ context. container_remap . insert ( old_id, new_id) ;
281+ Self :: update_positions_on_insert ( context. to_delete , * context. index , 1 ) ;
282+ * context. index += 1 ;
283+ * context. index_shift += 1 ;
284+ }
269285 Ok ( ( ) )
270286 }
271287
0 commit comments