mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-07-31 20:21:51 -07:00
X.U.Stack: Add zipperFocusedAtFirstOf
This commit is contained in:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user