Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Action
- newtype TextOperation = TextOperation [Action]
- invertOperation :: TextOperation -> Text -> Either String TextOperation
- data Cursor = Cursor {}
- updateCursor :: Cursor -> TextOperation -> Cursor
- data AugmentedTextOperation = AugmentedTextOperation {}
Simple text operations
An action changes the text at the current position or advances the cursor.
newtype TextOperation Source
An edit on plain text documents. An operation consists of multiple actions that change the document at the current cursor position or advance the cursor. After applying all actions, the cursor must be at the end of the document.
:: TextOperation | An operation. |
-> Text | Document before the operation was applied. |
-> Either String TextOperation |
Computes the inverse of an operation. Useful for implementing undo.
Text operations augmented with cursor information
A cursor has a cursorPosition
and a cursorSelectionEnd
. Both are
zero-based indexes into the document. When nothing is selected,
cursorSelectionEnd
is equal to cursorPosition
. When there is a selection,
cursorPosition
is always the side of the selection that would move if you
pressed an arrow key.
updateCursor :: Cursor -> TextOperation -> Cursor Source
Update cursor with respect to an operation.
data AugmentedTextOperation Source
An operation bundled with the cursor position after the operation.