@@ -38,7 +38,6 @@ module Rasa.Internal.Range
38
38
import Rasa.Internal.Text
39
39
import Control.Lens
40
40
41
- import Data.Maybe
42
41
import Data.Monoid
43
42
import Data.List
44
43
import Data.Bifunctor
@@ -176,7 +175,8 @@ clampCoord txt (Coord row col) =
176
175
Coord (clamp 0 maxRow row) (clamp 0 maxColumn col)
177
176
where
178
177
maxRow = Y. countNewLines txt
179
- maxColumn = fromMaybe col (txt ^? asLines . ix row . to Y. length )
178
+ selectedRow = fst . Y. splitAtLine 1 . snd . Y. splitAtLine row $ txt
179
+ maxColumn = Y. length selectedRow
180
180
181
181
-- | This will restrict a given 'Range' to a valid one which lies within the given text.
182
182
clampRange :: Y. YiString -> CrdRange -> CrdRange
@@ -237,22 +237,15 @@ sizeOf txt = Coord (Y.countNewLines txt) (Y.length (txt ^. asLines . _last))
237
237
-- | A lens over text before a given 'Coord'
238
238
beforeC :: Coord -> Lens' Y. YiString Y. YiString
239
239
beforeC c@ (Coord row col) = lens getter setter
240
- where getter txt =
241
- txt ^.. asLines . taking (row + 1 ) traverse
242
- & _last %~ Y. take col
243
- & Y. concat
244
-
240
+ where getter txt = let (before, after) = Y. splitAtLine row $ txt
241
+ in before <> Y. take col after
245
242
setter old new = let suffix = old ^. afterC c
246
243
in new <> suffix
247
244
248
245
-- | A lens over text after a given 'Coord'
249
246
afterC :: Coord -> Lens' Y. YiString Y. YiString
250
247
afterC c@ (Coord row col) = lens getter setter
251
- where getter txt =
252
- txt ^.. asLines . dropping row traverse
253
- & _head %~ Y. drop col
254
- & Y. concat
255
-
248
+ where getter txt = Y. drop col . snd . Y. splitAtLine row $ txt
256
249
setter old new = let prefix = old ^. beforeC c
257
250
in prefix <> new
258
251
0 commit comments