coreygirard/elm-zipper/1.0.0

Zipper.StringStringString.WithCursor

Not a clear special case or general case of any of the other zipper types.

Definition

type Zipper
= CursorLeft ( List Char, ( Char, List Char ), List Char )
| CursorRight ( List Char, ( List Char, Char ), List Char )
| CursorNone ( List Char, List Char )

A list type that must contain at least one element

Create

Create a new Zipper

empty --> CursorNone ( [], [] )

Apply key

Matches what happens when hitting the arrow left key without holding Shift.

-- shown as String instead of List Char for readability
CursorNone ( "ab", "cd" )
    |> arrowLeft
    == CursorNone ( "a", "bcd" )


CursorNone ( "", "cd" )
    |> arrowLeft
    == CursorNone ( "", "cd" )


CursorLeft ( "ab", "cde", "fg" )
    |> arrowLeft
    == CursorNone ( "ab", "cdefg" )


CursorRight ( "ab", "cde", "fg" )
    |> arrowLeft
    == CursorNone ( "ab", "cdefg" )

Matches what happens when hitting the arrow left key while holding Shift.

-- shown as String instead of List Char for readability
CursorNone ( "ab", "cd" )
    |> arrowLeftWithShift
    == CursorLeft ( "a", "b", "cd" )


CursorNone ( "", "cd" )
    |> arrowLeftWithShift
    == CursorNone ( "", "cd" )


CursorLeft ( "ab", "cde", "fg" )
    |> arrowLeftWithShift
    == CursorLeft ( "a", "bcde", "fg" )


CursorLeft ( "", "cde", "fg" )
    |> arrowLeftWithShift
    == CursorLeft ( "", "cde", "fg" )


CursorRight ( "ab", "cde", "fg" )
    |> arrowLeftWithShift
    == CursorNone ( "ab", "cd", "efg" )

Matches what happens when hitting the arrow right key without holding Shift.

-- shown as String instead of List Char for readability
CursorNone ( "ab", "cd" )
    |> arrowRight
    == CursorNone ( "abc", "d" )


CursorNone ( "ab", "" )
    |> arrowRight
    == CursorNone ( "ab", "" )


CursorLeft ( "ab", "cde", "fg" )
    |> arrowRight
    == CursorNone ( "abcde", "fg" )


CursorRight ( "ab", "cde", "fg" )
    |> arrowRight
    == CursorNone ( "abcde", "fg" )

Matches what happens when hitting the arrow right key while holding Shift.

-- shown as String instead of List Char for readability
CursorNone ( "ab", "cd" )
    |> arrowRightWithShift
    == CursorLeft ( "a", "b", "cd" )


CursorNone ( "ab", "" )
    |> arrowRightWithShift
    == CursorNone ( "", "cd" )


CursorLeft ( "ab", "cde", "fg" )
    |> arrowRightWithShift
    == CursorLeft ( "abc", "de", "fg" )


CursorRight ( "ab", "cde", "" )
    |> arrowRightWithShift
    == CursorLeft ( "ab", "cde", "" )


CursorRight ( "ab", "cde", "fg" )
    |> arrowRightWithShift
    == CursorNone ( "ab", "cdef", "g" )
typeKey : Char -> Zipper -> Zipper

Matches what happens when hitting a non-arrow key

-- shown as String instead of List Char for readability
CursorNone ( "ab", "cd" )
    |> arrowRightWithShift "z"
    == CursorNone ( "abz", "cd" )


CursorLeft ( "ab", "cde", "fg" )
    |> arrowRightWithShift
    == CursorNone ( "abz", "fg" )


CursorRight ( "ab", "cde", "fg" )
    |> arrowRightWithShift
    == CursorNone ( "abz", "fg" )