~jaro/balkon

ref: 3e36005fb819e46423c4afe02d3f77d7571e9b2b balkon/src/Data/Text/ParagraphLayout/Internal/WithSpan.hs -rw-r--r-- 1.2 KiB
3e36005fJaro Update changelog on numbers and neutrals. 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Data.Text.ParagraphLayout.Internal.WithSpan
    ( WithSpan (WithSpan)
    , allBoxes
    )
where

import Data.Text.ParagraphLayout.Internal.BiDiLevels
import Data.Text.ParagraphLayout.Internal.ResolvedBox
import Data.Text.ParagraphLayout.Internal.ResolvedSpan
import Data.Text.ParagraphLayout.Internal.TextContainer

-- | Wrapper for temporarily mapping the relationship to a `ResolvedSpan`.
data WithSpan d a = WithSpan (ResolvedSpan d) a

instance Functor (WithSpan d) where
    fmap f (WithSpan s a) = WithSpan s (f a)

instance TextContainer a => TextContainer (WithSpan d a) where
    getText (WithSpan _ c) = getText c

instance SeparableTextContainer a => SeparableTextContainer (WithSpan d a) where
    splitTextAt8 n (WithSpan rs c) = (WithSpan rs c1, WithSpan rs c2)
        where (c1, c2) = splitTextAt8 n c
    dropWhileStart p (WithSpan rs c) = WithSpan rs (dropWhileStart p c)
    dropWhileEnd p (WithSpan rs c) = WithSpan rs (dropWhileEnd p c)

instance WithLevel a => WithLevel (WithSpan d a) where
    level (WithSpan _ x) = level x

boxes :: WithSpan d a -> [ResolvedBox d]
boxes (WithSpan s _) = spanBoxes s

allBoxes :: (Foldable f, Functor f) => f (WithSpan d a) -> [ResolvedBox d]
allBoxes xs = foldr union [] $ fmap boxes xs