HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduletext-zipper-0.13Haskell2010

Data.Text.Zipper

This module provides a two-dimensional text zipper data structure. This structure represents a body of text and an editing cursor which can be moved throughout the text, along with a set of editing transformations.

Text zippers are generalized over the set of data types that might be used to store lists of characters (e.g., String, Text, etc.). As a result, the most general way to create a text zipper is to use mkZipper and provide all of the functions required to manipulate the underlying text data.

Implementations using Text and String are provided.

  • 1 type
  • 33 values
  • Packagetext-zipper-0.13
  • Exports34
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceZipper.hs

Construction and extraction

10 declarations
valuemkZipper
  1. :: Monoid a
  2. => (Char -> a)

    A singleton constructor.

  3. -> (Int -> a -> a)
  4. -> (Int -> a -> a)
  5. -> (a -> Int)
  6. -> (a -> Char)
  7. -> (a -> a)
  8. -> (a -> Bool)
  9. -> (a -> [a])
  10. -> (a -> [Char])

    toList.

  11. -> [a]

    The initial lines of text.

  12. -> Maybe Int

    Limit to this many lines of text (Nothing means no limit).

  13. -> TextZipper a
#

Create a zipper using a custom text storage type. Takes the initial text as well as all of the functions necessary to manipulate the underlying text values.

valuecursorPosition :: TextZipper a -> (Int, Int)
#

Get the cursor position of the zipper; returns (row, col). row ranges from [0..num_rows-1] inclusive; col ranges from [0..length of current line] inclusive. Column values equal to line width indicate a cursor that is just past the end of a line of text.

Navigation functions

10 declarations
valuemoveRight :: Monoid a => TextZipper a -> TextZipper a
#

Move the cursor right by one position. If the cursor is at the end of a line, the cursor is moved to the first position of the following line (if any).

valuemoveLeft :: Monoid a => TextZipper a -> TextZipper a
#

Move the cursor left by one position. If the cursor is at the beginning of a line, the cursor is moved to the last position of the preceding line (if any).

valuemoveUp :: Monoid a => TextZipper a -> TextZipper a
#

Move the cursor up by one row. If there no are rows above the current one, move to the first position of the current row. If the row above is shorter, move to the end of that row.

valuemoveDown :: Monoid a => TextZipper a -> TextZipper a
#

Move the cursor down by one row. If there are no rows below the current one, move to the last position of the current row. If the row below is shorter, move to the end of that row.

Inspection functions

3 declarations
valuecurrentChar :: TextZipper a -> Maybe Char
#

Get the Char on which the cursor currently resides. If the cursor is at the end of the text or the text is empty return Nothing.

valuenextChar :: Monoid a => TextZipper a -> Maybe Char
#

Get the Char after the cursor position. If the cursor is at the end of a line return the first character of the next line, or if that one is empty as well, return Nothing.

Editing functions

10 declarations
valueinsertChar :: Monoid a => Char -> TextZipper a -> TextZipper a
#

Insert a character at the current cursor position.

If the character is a newline, break the current line.

If the character is non-printable, ignore it.

Otherwise insert the character and move the cursor one position to the right.

valuedeleteChar :: Monoid a => TextZipper a -> TextZipper a
#

Delete the character at the cursor position. Leaves the cursor position unchanged. If the cursor is at the end of a line of text, this combines the line with the line below.

valuekillToEOL :: Monoid a => TextZipper a -> TextZipper a
#

Remove all text from the cursor position to the end of the current line. If the cursor is at the beginning of a line and the line is empty, the entire line will be removed.

valuekillToEOF :: Monoid a => TextZipper a -> TextZipper a
#

Remove all text from the cursor position to the end of the text zipper. If the cursor is at the beginning of a line and the line is empty, the entire line will be removed.

valuetransposeChars :: Monoid a => TextZipper a -> TextZipper a
#

Transpose the character before the cursor with the one at the cursor position and move the cursor one position to the right. If the cursor is at the end of the current line, transpose the current line's last two characters.