on develop help sign in
Fix deletion of items in traverseDMapWithKeyWithAdjustWithMove
commitff9351a1859a07f8f3892d6381e9d5d0cd500d5d authorRyan Trinkle <ryan.trinkle@gmail.com> dateFri 17 Feb 2017, 00:14 (10 years ago) parente511841
1 file changed+6−6
src/Reflex/Dom/Builder/Immediate.hs+6−6
src/Reflex/Dom/Builder/Immediate.hs+6−6
@@ -470,14 +470,14 @@ instance (Reflex t, MonadAdjust t m, MonadIO m, MonadHold t m, PerformEvent t m,
470470 if DMap.null p then return Nothing else return $ Just $ do
471471 let collectIfMoved :: forall a. k a -> DMapEdit k (Compose ((,,) DOM.DocumentFragment DOM.Text) v') a -> Performable m (Constant (Maybe DOM.DocumentFragment) a)
472472 collectIfMoved k e = do
473− Just thisPlaceholder <- return $ Map.lookup (Some.This k) phsBefore
474− let nextPlaceholder = maybe lastPlaceholder snd $ Map.lookupGT (Some.This k) phsBefore
473+ let mThisPlaceholder = Map.lookup (Some.This k) phsBefore -- Will be Nothing if this element wasn't present before
474+ nextPlaceholder = maybe lastPlaceholder snd $ Map.lookupGT (Some.This k) phsBefore
475475 case dmapEditMoved e of
476476 False -> do
477− thisPlaceholder `deleteUpTo` nextPlaceholder
477+ mapM_ (`deleteUpTo` nextPlaceholder) mThisPlaceholder
478478 return $ Constant Nothing
479479 True -> do
480− Constant . Just <$> thisPlaceholder `collectUpTo` nextPlaceholder
480+ Constant <$> mapM (`collectUpTo` nextPlaceholder) mThisPlaceholder
481481 collected <- DMap.traverseWithKey collectIfMoved p
482482 let phsAfter = fromMaybe phsBefore $ apply (weakenPatchDMapWithMoveWith (\(Compose (_, ph, _)) -> ph) p_) phsBefore --TODO: Don't recompute this
483483 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,
489489 DMapEdit_Delete _ -> do
490490 return ()
491491 DMapEdit_Move _ fromKey -> do
492− Just (Constant (Just df)) <- return $ DMap.lookup fromKey collected
493− df `insertBefore` nextPlaceholder
492+ Just (Constant mdf) <- return $ DMap.lookup fromKey collected
493+ mapM_ (`insertBefore` nextPlaceholder) mdf
494494 return $ Constant ()
495495 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
496496 return ()