Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a basic text editor widget. You'll need to
embed an Editor
in your application state and transform it with
handleEvent
when relevant events arrive. To get the contents
of the editor, just use getEditContents
. To modify it, use the
TextZipper
interface with applyEdit
.
The editor's HandleEvent
instance handles a set of basic input
events that should suffice for most purposes; see the source for a
complete list.
- data Editor
- editor :: Name -> ([String] -> Widget) -> Maybe Int -> String -> Editor
- getEditContents :: Editor -> [String]
- applyEdit :: (TextZipper String -> TextZipper String) -> Editor -> Editor
- editContentsL :: Lens' Editor (TextZipper String)
- editDrawContentsL :: Lens' Editor ([String] -> Widget)
- renderEditor :: Editor -> Widget
- editAttr :: AttrName
Documentation
Editor state. Editors support the following events by default:
- Ctrl-a: go to beginning of line
- Ctrl-e: go to end of line
- Ctrl-d, Del: delete character at cursor position
- Backspace: delete character prior to cursor position
- Ctrl-k: delete all from cursor to end of line
- Arrow keys: move cursor
- Enter: break the current line at the cursor position
Constructing an editor
:: Name | The editor's name (must be unique) |
-> ([String] -> Widget) | The content rendering function |
-> Maybe Int | The limit on the number of lines in the editor ( |
-> String | The initial content |
-> Editor |
Construct an editor.
Reading editor contents
getEditContents :: Editor -> [String] Source
Get the contents of the editor.
Editing text
:: (TextZipper String -> TextZipper String) | The |
-> Editor | |
-> Editor |
Apply an editing operation to the editor's contents. Bear in mind that you should only apply zipper operations that operate on the current line; the editor will only ever render the first line of text.
Lenses for working with editors
Rendering editors
renderEditor :: Editor -> Widget Source
Turn an editor state value into a widget