module Rasa.Internal.BufActions
( overRange
, replaceRange
, deleteRange
, insertAt
, sizeOf
, getLineRange
) where
import Rasa.Internal.BufAction
import Rasa.Internal.Range
import Rasa.Internal.Text
import Control.Lens
import qualified Yi.Rope as Y
overRange :: CrdRange -> (Y.YiString -> Y.YiString) -> BufAction ()
overRange r f = getRange r >>= setRange r . f
deleteRange :: CrdRange -> BufAction ()
deleteRange r = replaceRange r ""
replaceRange :: CrdRange -> Y.YiString -> BufAction ()
replaceRange r txt = overRange r (const txt)
insertAt :: Coord -> Y.YiString -> BufAction ()
insertAt c = replaceRange r
where r = Range c c
type Row = Int
getLineRange :: Row -> BufAction (Maybe CrdRange)
getLineRange n = do
txt <- getText
let len = txt ^? asLines . ix n . to Y.length
return $ Range (Coord n 0) . Coord n <$> len