A class for tree types and representations of selections on tree types, as well as functions for converting between text and tree selections.
- type Path = [Int]
- root :: Path
- type Nav = Path -> Path
- up :: Nav
- into :: Int -> Nav
- down :: Nav
- left :: Nav
- right :: Nav
- sibling :: Int -> Nav
- class Tree p where
- children :: p -> [p]
- followM :: (Monad m, Tree t) => t -> Path -> m t
- follow :: Tree t => t -> Path -> t
- depth :: Tree t => t -> Int
- selectDepth :: Tree t => Int -> t -> [t]
- flatten :: Tree t => t -> [t]
- class Tree t => Selectable t where
- type TreeSelection = (Path, Int)
- select :: (Monad m, Tree t) => t -> TreeSelection -> m [t]
- allSelections :: Selectable a => a -> [TreeSelection]
- selectionToRange :: (Tree a, KnowsPosition a) => a -> TreeSelection -> Range
- rangeToSelection :: (Tree a, KnowsPosition a, Monad m) => a -> Range -> m TreeSelection
- posToPath :: (Tree a, KnowsPosition a) => a -> Pos -> Path
- isValidRange :: (KnowsPosition a, Selectable a) => a -> Range -> Bool
- suggest :: (Selectable a, KnowsPosition a) => a -> Range -> [TreeSelection]
- repair :: (KnowsPosition a, Selectable a) => a -> Range -> Range
Paths and navigation
A path in a tree. Each integer denotes the selection of a child; these indices are 0-relative.
Follows a path in a tree, returning the result in a monad.
Tells whether complete subranges of children may be selected in this tree. If not, valid TreeSelections in this tree always have a second element
Selection in a tree. The path indicates the left side of the selection; the int tells how many siblings to the right are included in the selection.
Enumerates all possible selections of a tree.
Computes the range of a valid selection.
Converts a specified range to a corresponding selection and returns it in a monad.
Returns the path to the deepest descendant whose range contains the specified position.
Tells whether the text selection corresponds to a tree selection.
Suggesting and fixing
Yields all possible selections, ordered by distance to the specified range, closest first.