@@ -156,8 +156,8 @@ yield new PackedPacksState(
156156 CollectionUtils .addIf (packs , payload , p -> canTransfer (target , p , options ));
157157 if (!packs .isEmpty ()) {
158158 yield this .reduce (newState , switch (destination .type ()) {
159- case AVAILABLE -> new PackListIntent .Disable (destination , ctx , packs );
160- case ENABLED -> new PackListIntent .Enable (destination , ctx , packs , position );
159+ case AVAILABLE -> new PackListIntent .Disable (destination , ctx , packs . reversed () );
160+ case ENABLED -> new PackListIntent .Enable (destination , ctx , packs . reversed () , position );
161161 });
162162 }
163163 }
@@ -246,11 +246,14 @@ private PackListState reduceList(PackListState state, PackListIntent.ListScoped
246246 List <Pack > ordered = sortByOrderOf (state .visiblePacks (), move .payload ());
247247 List <Pack > newPacks = new ObjectArrayList <>(state .packs ());
248248 int to = move .index ();
249+ int insertOffset = 0 ;
249250 for (Pack pack : ordered ) {
250251 int previous = newPacks .indexOf (pack );
251- int target = previous != -1 && previous < to ? to - 1 : to ;
252+ boolean isBeforeTo = previous != -1 && previous < to ;
253+ int target = isBeforeTo ? to - 1 : to + insertOffset ;
252254 newPacks .remove (pack );
253255 newPacks .add (Math .clamp (target , 0 , newPacks .size ()), pack );
256+ if (!isBeforeTo ) insertOffset ++;
254257 }
255258 yield newPacks .equals (state .packs ()) ? state : state .withPacks (newPacks , options );
256259 }
0 commit comments