-- | Gets the lines of a region (as a region), preserving newlines. Thus the
-- resulting list of regions is a partition of the original region.
--
-- The direction of the region is preserved and all smaller regions will
-- retain that direction.
--
-- Note that regions should never be empty, so it would be odd for this to
-- return an empty list...
linesOfRegionB :: Region -> BufferM [Region]
linesOfRegionB region = do
    let start = regionStart region
        direction = regionDirection region
    ls <- R.lines' <$> readRegionB region
    return $ case ls of
        [] -> []
        (l:ls') -> let initialRegion = mkRegion' direction start (start + fromIntegral (R.length l))
                   in scanl nextRegion initialRegion ls'

-- | Given some text and the previous region, finds the next region
-- (used for implementing linesOfRegionB, not generally useful)
linesOfRegionB :: Region -> BufferM [Region]
linesOfRegionB region = do
    let start = regionStart region
        direction = regionDirection region
    ls <- R.lines' <$> readRegionB region
    return $ case ls of
        [] -> []
        (l:ls') -> let initialRegion = mkRegion' direction start (start + fromIntegral (R.length l))
                   in scanl nextRegion initialRegion ls'

-- | Given some text and the previous region, finds the next region
-- (used for implementing linesOfRegionB, not generally useful)
linesOfRegionB region = do
    let start = regionStart region
        direction = regionDirection region
    ls <- R.lines' <$> readRegionB region
    return $ case ls of
        [] -> []
        (l:ls') -> let initialRegion = mkRegion' direction start (start + fromIntegral (R.length l))
                   in scanl nextRegion initialRegion ls'

-- | Given some text and the previous region, finds the next region
-- (used for implementing linesOfRegionB, not generally useful)