Update single selection to be under mouse while dragging

This commit is contained in:
2024-11-25 18:29:01 +00:00
parent 887ae2477c
commit 79bc3b2ddf
3 changed files with 101 additions and 94 deletions
+8 -1
View File
@@ -280,7 +280,7 @@ shiftInvItems ::
IM.IntMap (SelectionItem a) ->
World ->
World
shiftInvItems k x ab bn xs ss w = fromMaybe w $ do
shiftInvItems k x ab bn xs ss w = setSelWhileDragging . fromMaybe w $ do
let xk = fst x
guard $ xk == k || xk + 1 == k || xk -1 == k
(maxi,_) <- IS.maxView xs
@@ -295,6 +295,13 @@ shiftInvItems k x ab bn xs ss w = fromMaybe w $ do
guard $ Just (k,maxi+1) < bn
return $ shiftInvItemsDown k xs w
setSelWhileDragging :: World -> World
setSelWhileDragging w = fromMaybe w $ do
(i,_,xs) <- w ^? hud . hudElement . diSelection . _Just
(k,j) <- w ^? input . mouseContext . mcoMaybeSelect . _Just
guard $ i == k && j `IS.member` xs
return $ w & hud . hudElement . diSelection . _Just . _2 .~ j
shiftInvItemsUp :: Int -> IS.IntSet -> World -> World
shiftInvItemsUp j is w = IS.foldl' f w is
where