| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NanoUI.Widgets.TextEditor
Description
The editing core every text field shares: a document, a selection and an
undo history, changed only by TextCommands. Keys and menu rows map onto
commands, and an app can run the same commands on a field.
Synopsis
- data TextCommand
- data TextMotion
- data Editor = Editor {}
- data EditorMode = EditorMode {
- modeMultiLine :: !Bool
- modeEditable :: !Bool
- modeCopyable :: !Bool
- singleLineMode :: EditorMode
- multiLineMode :: EditorMode
- editorModeCode :: EditorMode -> Int
- editorModeFromCode :: Int -> Maybe EditorMode
- editorFromBuffer :: TextBuffer -> Editor
- editorSelection :: Editor -> (Cursor, Cursor)
- hasSelection :: Editor -> Bool
- runCommand :: EditorMode -> TextCommand -> Editor -> Editor
- runCommandIO :: Context -> EditorMode -> TextCommand -> Editor -> IO Editor
- inputTextCommands :: EditorMode -> Input -> [TextCommand]
- keyCommand :: EditorMode -> Modifiers -> Key -> Maybe TextCommand
- data EditHistory = EditHistory {
- historyUndo :: ![EditGroup]
- historyRedo :: ![EditGroup]
- historyDepth :: !Int
- historyOpen :: !Bool
- data EditGroup = EditGroup {
- groupKind :: !EditKind
- groupEdits :: ![StoredEdit]
- groupBefore :: !(Cursor, Cursor)
- groupAfter :: !(Cursor, Cursor)
- data StoredEdit = StoredEdit !Cursor !ShortText !ShortText
- data EditKind
- emptyHistory :: EditHistory
- sealHistory :: EditHistory -> EditHistory
- canUndo :: EditHistory -> Bool
- canRedo :: EditHistory -> Bool
Commands
data TextCommand Source #
Something done to a text field. Commands that change text are undoable and replace the selection where one exists.
Constructors
| InsertText !Text | Replace the selection with text (typing, a snippet). |
| Delete !TextMotion | Delete the selection, or from the cursor to where the motion lands:
|
| Move !TextMotion !Bool | Move the cursor, extending the selection when the flag is set. |
| SelectAll | |
| Select !Cursor !Cursor | Select from the first position (the anchor) to the second (the cursor), clamped into the document. |
| Replace !Cursor !Cursor !Text | Replace the text between two positions, leaving the cursor after it. |
| ReplaceAll !Text | Replace the whole document as one undoable edit. |
| Undo | |
| Redo | |
| Cut | |
| Copy | |
| Paste |
Instances
| Eq TextCommand Source # | |
Defined in NanoUI.Widgets.TextCommand | |
| Show TextCommand Source # | |
Defined in NanoUI.Widgets.TextCommand Methods showsPrec :: Int -> TextCommand -> ShowS # show :: TextCommand -> String # showList :: [TextCommand] -> ShowS # | |
data TextMotion Source #
Where a motion takes the cursor.
Constructors
| CharLeft | |
| CharRight | |
| WordLeft | |
| WordRight | |
| LineStart | |
| LineEnd | |
| LineUp | |
| LineDown | |
| DocumentStart | |
| DocumentEnd |
Instances
| Eq TextMotion Source # | |
Defined in NanoUI.Widgets.TextCommand | |
| Bounded TextMotion Source # | |
Defined in NanoUI.Widgets.TextCommand | |
| Enum TextMotion Source # | |
Defined in NanoUI.Widgets.TextCommand Methods succ :: TextMotion -> TextMotion # pred :: TextMotion -> TextMotion # toEnum :: Int -> TextMotion # fromEnum :: TextMotion -> Int # enumFrom :: TextMotion -> [TextMotion] # enumFromThen :: TextMotion -> TextMotion -> [TextMotion] # enumFromTo :: TextMotion -> TextMotion -> [TextMotion] # enumFromThenTo :: TextMotion -> TextMotion -> TextMotion -> [TextMotion] # | |
| Show TextMotion Source # | |
Defined in NanoUI.Widgets.TextCommand Methods showsPrec :: Int -> TextMotion -> ShowS # show :: TextMotion -> String # showList :: [TextMotion] -> ShowS # | |
Editors
A document with its selection (the cursor is the buffer's, the anchor the other end) and history.
Constructors
| Editor | |
Fields
| |
data EditorMode Source #
How a field lets its document be changed.
Constructors
| EditorMode | |
Fields
| |
Instances
| Eq EditorMode Source # | |
Defined in NanoUI.Widgets.TextEditor | |
| Show EditorMode Source # | |
Defined in NanoUI.Widgets.TextEditor Methods showsPrec :: Int -> EditorMode -> ShowS # show :: EditorMode -> String # showList :: [EditorMode] -> ShowS # | |
editorModeCode :: EditorMode -> Int Source #
A mode as a store integer, so a command sent to a widget id between frames knows what kind of field it edits.
editorModeFromCode :: Int -> Maybe EditorMode Source #
editorFromBuffer :: TextBuffer -> Editor Source #
hasSelection :: Editor -> Bool Source #
runCommand :: EditorMode -> TextCommand -> Editor -> Editor Source #
Run a command that needs no clipboard. Cut, Copy and Paste do
nothing here; runCommandIO runs them.
runCommandIO :: Context -> EditorMode -> TextCommand -> Editor -> IO Editor Source #
runCommand, with the clipboard commands going through the context's
clipboard.
Key bindings
inputTextCommands :: EditorMode -> Input -> [TextCommand] Source #
This frame's typing and keys as commands, typed characters first. Ctrl turns characters into shortcuts. Ctrl with Alt is AltGr on many layouts, so its characters are typed like plain ones.
keyCommand :: EditorMode -> Modifiers -> Key -> Maybe TextCommand Source #
The command a key runs. Ctrl or Alt turns character and deletion keys into word motions, and Shift extends the selection.
History
data EditHistory Source #
Constructors
| EditHistory | |
Fields
| |
Instances
| Eq EditHistory Source # | |
Defined in NanoUI.Widgets.TextEditor | |
| Show EditHistory Source # | |
Defined in NanoUI.Widgets.TextEditor Methods showsPrec :: Int -> EditHistory -> ShowS # show :: EditHistory -> String # showList :: [EditHistory] -> ShowS # | |
Edits undone and redone as one step.
Constructors
| EditGroup | |
Fields
| |
data StoredEdit Source #
An edit as history keeps it. Undo steps live for the life of a field and
are rarely replayed, so their texts are compact copies: they cost two
words less than a Text, and never keep alive the larger text a slice
was cut from.
Constructors
| StoredEdit !Cursor !ShortText !ShortText |
Instances
| Eq StoredEdit Source # | |
Defined in NanoUI.Widgets.TextEditor | |
| Show StoredEdit Source # | |
Defined in NanoUI.Widgets.TextEditor Methods showsPrec :: Int -> StoredEdit -> ShowS # show :: StoredEdit -> String # showList :: [StoredEdit] -> ShowS # | |
What started a group of edits, which decides what may join it.
Constructors
| EditTyping | |
| EditDeleting | |
| EditOther |
sealHistory :: EditHistory -> EditHistory Source #
Start the next edit in a group of its own.
canUndo :: EditHistory -> Bool Source #
canRedo :: EditHistory -> Bool Source #