-- | The commands text fields run: the same ones for keys, context menus and
-- app code.
module NanoUI.Widgets.TextCommand
  ( TextCommand (..)
  , TextMotion (..)
  ) where

import Data.Text (Text)
import NanoUI.Widgets.TextBuffer (Cursor)

-- | Where a motion takes the cursor.
data TextMotion
  = CharLeft
  | CharRight
  | WordLeft
  | WordRight
  | LineStart
  | LineEnd
  | LineUp
  | LineDown
  | DocumentStart
  | DocumentEnd
  deriving (TextMotion -> TextMotion -> Bool
(TextMotion -> TextMotion -> Bool)
-> (TextMotion -> TextMotion -> Bool) -> Eq TextMotion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextMotion -> TextMotion -> Bool
== :: TextMotion -> TextMotion -> Bool
$c/= :: TextMotion -> TextMotion -> Bool
/= :: TextMotion -> TextMotion -> Bool
Eq, Int -> TextMotion -> ShowS
[TextMotion] -> ShowS
TextMotion -> String
(Int -> TextMotion -> ShowS)
-> (TextMotion -> String)
-> ([TextMotion] -> ShowS)
-> Show TextMotion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextMotion -> ShowS
showsPrec :: Int -> TextMotion -> ShowS
$cshow :: TextMotion -> String
show :: TextMotion -> String
$cshowList :: [TextMotion] -> ShowS
showList :: [TextMotion] -> ShowS
Show, Int -> TextMotion
TextMotion -> Int
TextMotion -> [TextMotion]
TextMotion -> TextMotion
TextMotion -> TextMotion -> [TextMotion]
TextMotion -> TextMotion -> TextMotion -> [TextMotion]
(TextMotion -> TextMotion)
-> (TextMotion -> TextMotion)
-> (Int -> TextMotion)
-> (TextMotion -> Int)
-> (TextMotion -> [TextMotion])
-> (TextMotion -> TextMotion -> [TextMotion])
-> (TextMotion -> TextMotion -> [TextMotion])
-> (TextMotion -> TextMotion -> TextMotion -> [TextMotion])
-> Enum TextMotion
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: TextMotion -> TextMotion
succ :: TextMotion -> TextMotion
$cpred :: TextMotion -> TextMotion
pred :: TextMotion -> TextMotion
$ctoEnum :: Int -> TextMotion
toEnum :: Int -> TextMotion
$cfromEnum :: TextMotion -> Int
fromEnum :: TextMotion -> Int
$cenumFrom :: TextMotion -> [TextMotion]
enumFrom :: TextMotion -> [TextMotion]
$cenumFromThen :: TextMotion -> TextMotion -> [TextMotion]
enumFromThen :: TextMotion -> TextMotion -> [TextMotion]
$cenumFromTo :: TextMotion -> TextMotion -> [TextMotion]
enumFromTo :: TextMotion -> TextMotion -> [TextMotion]
$cenumFromThenTo :: TextMotion -> TextMotion -> TextMotion -> [TextMotion]
enumFromThenTo :: TextMotion -> TextMotion -> TextMotion -> [TextMotion]
Enum, TextMotion
TextMotion -> TextMotion -> Bounded TextMotion
forall a. a -> a -> Bounded a
$cminBound :: TextMotion
minBound :: TextMotion
$cmaxBound :: TextMotion
maxBound :: TextMotion
Bounded)

-- | Something done to a text field. Commands that change text are undoable
-- and replace the selection where one exists.
data TextCommand
  = -- | Replace the selection with text (typing, a snippet).
    InsertText !Text
  | -- | Delete the selection, or from the cursor to where the motion lands:
    -- @Delete CharLeft@ is Backspace, @Delete WordRight@ Ctrl+Delete.
    Delete !TextMotion
  | -- | Move the cursor, extending the selection when the flag is set.
    Move !TextMotion !Bool
  | SelectAll
  | -- | Select from the first position (the anchor) to the second (the
    -- cursor), clamped into the document.
    Select !Cursor !Cursor
  | -- | Replace the text between two positions, leaving the cursor after it.
    Replace !Cursor !Cursor !Text
  | -- | Replace the whole document as one undoable edit.
    ReplaceAll !Text
  | Undo
  | Redo
  | Cut
  | Copy
  | Paste
  deriving (TextCommand -> TextCommand -> Bool
(TextCommand -> TextCommand -> Bool)
-> (TextCommand -> TextCommand -> Bool) -> Eq TextCommand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextCommand -> TextCommand -> Bool
== :: TextCommand -> TextCommand -> Bool
$c/= :: TextCommand -> TextCommand -> Bool
/= :: TextCommand -> TextCommand -> Bool
Eq, Int -> TextCommand -> ShowS
[TextCommand] -> ShowS
TextCommand -> String
(Int -> TextCommand -> ShowS)
-> (TextCommand -> String)
-> ([TextCommand] -> ShowS)
-> Show TextCommand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextCommand -> ShowS
showsPrec :: Int -> TextCommand -> ShowS
$cshow :: TextCommand -> String
show :: TextCommand -> String
$cshowList :: [TextCommand] -> ShowS
showList :: [TextCommand] -> ShowS
Show)