@@ -470,14 +470,14 @@ instance (Reflex t, MonadAdjust t m, MonadIO m, MonadHold t m, PerformEvent t m,
470 if DMap.null p then return Nothing else return $ Just $ do
470 if DMap.null p then return Nothing else return $ Just $ do
471 let collectIfMoved :: forall a. k a -> DMapEdit k (Compose ((,,) DOM.DocumentFragment DOM.Text) v') a -> Performable m (Constant (Maybe DOM.DocumentFragment) a)
471 let collectIfMoved :: forall a. k a -> DMapEdit k (Compose ((,,) DOM.DocumentFragment DOM.Text) v') a -> Performable m (Constant (Maybe DOM.DocumentFragment) a)
472 collectIfMoved k e = do
472 collectIfMoved k e = do
473− Just thisPlaceholder <- return $ Map.lookup (Some.This k) phsBefore
473+ let mThisPlaceholder = Map.lookup (Some.This k) phsBefore -- Will be Nothing if this element wasn't present before
474− let nextPlaceholder = maybe lastPlaceholder snd $ Map.lookupGT (Some.This k) phsBefore
474+ nextPlaceholder = maybe lastPlaceholder snd $ Map.lookupGT (Some.This k) phsBefore
475 case dmapEditMoved e of
475 case dmapEditMoved e of
476 False -> do
476 False -> do
477− thisPlaceholder `deleteUpTo` nextPlaceholder
477+ mapM_ (`deleteUpTo` nextPlaceholder) mThisPlaceholder
478 return $ Constant Nothing
478 return $ Constant Nothing
479 True -> do
479 True -> do
480− Constant . Just <$> thisPlaceholder `collectUpTo` nextPlaceholder
480+ Constant <$> mapM (`collectUpTo` nextPlaceholder) mThisPlaceholder
481 collected <- DMap.traverseWithKey collectIfMoved p
481 collected <- DMap.traverseWithKey collectIfMoved p
482 let phsAfter = fromMaybe phsBefore $ apply (weakenPatchDMapWithMoveWith (\(Compose (_, ph, _)) -> ph) p_) phsBefore --TODO: Don't recompute this
482 let phsAfter = fromMaybe phsBefore $ apply (weakenPatchDMapWithMoveWith (\(Compose (_, ph, _)) -> ph) p_) phsBefore --TODO: Don't recompute this
483 let placeFragment :: forall a. k a -> DMapEdit k (Compose ((,,) DOM.DocumentFragment DOM.Text) v') a -> Performable m (Constant () a)
483 let placeFragment :: forall a. k a -> DMapEdit k (Compose ((,,) DOM.DocumentFragment DOM.Text) v') a -> Performable m (Constant () a)
@@ -489,8 +489,8 @@ instance (Reflex t, MonadAdjust t m, MonadIO m, MonadHold t m, PerformEvent t m,
489 DMapEdit_Delete _ -> do
489 DMapEdit_Delete _ -> do
490 return ()
490 return ()
491 DMapEdit_Move _ fromKey -> do
491 DMapEdit_Move _ fromKey -> do
492− Just (Constant (Just df)) <- return $ DMap.lookup fromKey collected
492+ Just (Constant mdf) <- return $ DMap.lookup fromKey collected
493− df `insertBefore` nextPlaceholder
493+ mapM_ (`insertBefore` nextPlaceholder) mdf
494 return $ Constant ()
494 return $ Constant ()
495 mapM_ (\(k :=> v) -> void $ placeFragment k v) $ DMap.toDescList p -- We need to go in reverse order here, to make sure the placeholders are in the right spot at the right time
495 mapM_ (\(k :=> v) -> void $ placeFragment k v) $ DMap.toDescList p -- We need to go in reverse order here, to make sure the placeholders are in the right spot at the right time
496 return ()
496 return ()