ot-0.1.2: Real-time collaborative editing with Operational Transformation

Safe HaskellNone




Simple text operations

data Action Source

An action changes the text at the current position or advances the cursor.


Retain !Int

Skip the next n characters.

Insert !Text

Insert the given text at the current position.

Delete !Int

Delete the next n characters.

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 [Action] 



:: 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

data Cursor Source

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 -> CursorSource

Update cursor with respect to an operation.