X.U.Stack: Add zipperFocusedAtFirstOf

This commit is contained in:
Tony Zorman
2023-09-19 09:13:15 +02:00
parent 52a40f376c
commit 8ee129483a
6 changed files with 47 additions and 61 deletions

View File

@@ -27,6 +27,7 @@ module XMonad.Util.Stack ( -- * Usage
, toIndex
, fromTags
, toTags
, zipperFocusedAtFirstOf
-- * 'Zipper' manipulation functions
-- ** Insertion, movement
@@ -123,6 +124,18 @@ toTags Nothing = []
toTags (Just s) = map Left (reverse . W.up $ s) ++ [Right . W.focus $ s]
++ map Left (W.down s)
-- | @differentiate zs xs@ takes the first @z@ from @z2 that also belongs to
-- @xs@ and turns @xs@ into a stack with @z@ being the current element. Acts
-- as 'XMonad.StackSet.differentiate' if @zs@ and @xs@ don't intersect.
zipperFocusedAtFirstOf :: Eq q => [q] -> [q] -> Zipper q
zipperFocusedAtFirstOf [] xs = W.differentiate xs
zipperFocusedAtFirstOf (z : zs) xs
| z `elem` xs = Just $
W.Stack { W.focus = z
, W.up = reverse $ takeWhile (/= z) xs
, W.down = drop 1 $ dropWhile (/= z) xs
}
| otherwise = zipperFocusedAtFirstOf zs xs
-- * Zipper functions