text-region-0.1.0.1: Marking text regions

Safe HaskellNone
LanguageHaskell2010

Data.Text.Region.Types

Synopsis

Documentation

type Size = Point Source #

Distance between Points is measured in lines and columns. And it is defined, that distance between point at l:c and point (l + 1):0 is one line no matter c is because we need to go to new line to reach destination point Columns are taken into account only if points are on the same line

(.-.) :: Point -> Point -> Point Source #

pt .-. base is distance from base to pt Distance can't be less then zero lines and columns

(.+.) :: Point -> Point -> Point Source #

Opposite to ".-.", (pt .-. base) .+. base = pt

newtype Map Source #

Main idea is that there are only two basic actions, that changes regions: inserting and cutting When something is cutted out or inserted in, Region positions must be updated All editings can be represented as many cuts and inserts, so we can combine them to get function which maps source regions to regions on updated data Because insert is dual to cut (and therefore composes something like iso), we can also get function to map regions back Combining this functions while edit, we get function, that maps regions from source data to edited one To get back function, we must also combine opposite actions, or we can represent actions as Iso Same idea goes for modifying contents, represent each action as isomorphism and combine them together

Constructors

Map 

Instances

Monoid Map Source # 

Methods

mempty :: Map #

mappend :: Map -> Map -> Map #

mconcat :: [Map] -> Map #

Group Map Source # 

Methods

invert :: Map -> Map #

pow :: Integral x => Map -> x -> Map #

ApplyMap Map Source # 

Methods

applyMap :: Map -> Map -> Map Source #

type Contents a = [a] Source #

Contents is list of lines, list must have at least one (maybe empty) line

emptyContents :: Monoid a => Contents a Source #

Empty contents are contents with one empty line

splitCts :: Editable a => Point -> Contents a -> (Contents a, Contents a) Source #

Split Contents at some Point

splitted :: Editable a => Point -> Iso' (Contents a) (Contents a, Contents a) Source #

Get splitted Contents at some Point

class Monoid a => Editable a where Source #

Something editable, string types implements this

Minimal complete definition

splitContents, contentsLength, splitLines, joinLines

Methods

splitContents :: Int -> a -> (a, a) Source #

Split editable at some position

contentsLength :: a -> Int Source #

splitLines :: a -> [a] Source #

joinLines :: [a] -> a Source #

contents :: (Editable a, Editable b) => Iso a b (Contents a) (Contents b) Source #

Get Contents for some Editable, splitting lines

by :: Editable a => a -> Contents a Source #

measure :: Editable s => Contents s -> Size Source #

Contents Size

data Replace s Source #

Serializable edit action

Constructors

Replace 

Fields

replaceWith :: forall s s. Lens (Replace s) (Replace s) (Contents s) (Contents s) Source #

newtype Chain e s Source #

Chain of edit actions

Constructors

Chain 

Fields

Instances

EditAction e s => EditAction (Chain e) s Source # 

Methods

replace :: Region -> Contents s -> Chain e s Source #

actionMap :: Chain e s -> Map Source #

perform :: Chain e s -> State (Contents s) (Chain e s) Source #

Eq (e s) => Eq (Chain e s) Source # 

Methods

(==) :: Chain e s -> Chain e s -> Bool #

(/=) :: Chain e s -> Chain e s -> Bool #

Show (e s) => Show (Chain e s) Source # 

Methods

showsPrec :: Int -> Chain e s -> ShowS #

show :: Chain e s -> String #

showList :: [Chain e s] -> ShowS #

Monoid (Chain e s) Source # 

Methods

mempty :: Chain e s #

mappend :: Chain e s -> Chain e s -> Chain e s #

mconcat :: [Chain e s] -> Chain e s #

ToJSON (e s) => ToJSON (Chain e s) Source # 

Methods

toJSON :: Chain e s -> Value #

toEncoding :: Chain e s -> Encoding #

toJSONList :: [Chain e s] -> Value #

toEncodingList :: [Chain e s] -> Encoding #

FromJSON (e s) => FromJSON (Chain e s) Source # 

Methods

parseJSON :: Value -> Parser (Chain e s) #

parseJSONList :: Value -> Parser [Chain e s] #

ApplyMap (e s) => ApplyMap (Chain e s) Source # 

Methods

applyMap :: Map -> Chain e s -> Chain e s Source #

chain :: forall e s e s. Iso (Chain e s) (Chain e s) [e s] [e s] Source #

data ActionIso e Source #

Some action with its inverse

Constructors

ActionIso 

Fields

action :: forall e. Lens' (ActionIso e) e Source #

actionBack :: forall e. Lens' (ActionIso e) e Source #

data EditState s r Source #

Edit state

Constructors

EditState 

Fields

Instances

(Editable s, ToJSON s, ToJSON r) => ToJSON (EditState s r) Source # 
(Editable s, FromJSON s, FromJSON r) => FromJSON (EditState s r) Source # 
MonadState (EditState s r) (EditM s r) Source # 

Methods

get :: EditM s r (EditState s r) #

put :: EditState s r -> EditM s r () #

state :: (EditState s r -> (a, EditState s r)) -> EditM s r a #

editState :: Editable s => s -> r -> EditState s r Source #

Make edit state for contents

history :: forall s r. Lens' (EditState s r) (ActionStack (Edit s)) Source #

edited :: forall s r. Lens' (EditState s r) (Contents s) Source #

regions :: forall s r r. Lens (EditState s r) (EditState s r) r r Source #

newtype EditM s r a Source #

Constructors

EditM 

Fields

Instances

Monad (EditM s r) Source # 

Methods

(>>=) :: EditM s r a -> (a -> EditM s r b) -> EditM s r b #

(>>) :: EditM s r a -> EditM s r b -> EditM s r b #

return :: a -> EditM s r a #

fail :: String -> EditM s r a #

Functor (EditM s r) Source # 

Methods

fmap :: (a -> b) -> EditM s r a -> EditM s r b #

(<$) :: a -> EditM s r b -> EditM s r a #

Applicative (EditM s r) Source # 

Methods

pure :: a -> EditM s r a #

(<*>) :: EditM s r (a -> b) -> EditM s r a -> EditM s r b #

(*>) :: EditM s r a -> EditM s r b -> EditM s r b #

(<*) :: EditM s r a -> EditM s r b -> EditM s r a #

MonadState (EditState s r) (EditM s r) Source # 

Methods

get :: EditM s r (EditState s r) #

put :: EditState s r -> EditM s r () #

state :: (EditState s r -> (a, EditState s r)) -> EditM s r a #

module Data.Group