Module

Web.Util.TextCursor

Package
purescript-textcursor
Repository
MonoidMusician/purescript-textcursor

#TextCursor Source

newtype TextCursor

The TextCursor type represents text selection within an input element. It consists of three regions of text: the text before the cursor, the text selected, and the text after the selection. This allows replacements to occur while keeping intact the cursor position/selection.

Constructors

Instances

#mkTextCursor Source

mkTextCursor :: String -> String -> String -> TextCursor

Create a TextCursor from three strings.

#genTextCursor Source

genTextCursor :: forall m. MonadRec m => MonadGen m => m TextCursor

#content Source

content :: TextCursor -> String

Get the current text in the field. (Everything before, inside, and after the selection.)

#length Source

length :: TextCursor -> Int

Get the content length.

#null Source

null :: TextCursor -> Boolean

Test whether there is no content.

#empty Source

empty :: TextCursor

An empty input field. No selection.

#single Source

single :: Setter' TextCursor String -> String -> TextCursor

Apply a Lens setting a value to an empty TextCursor. When used with _before, _selected, or _after this will provide a TextCursor with only one non-empty field.

#_before Source

_before :: Lens' TextCursor String

Lens for the text before the selection. Empty if the cursor is at the beginning or the selection starts from the beginning.

#_selected Source

_selected :: Lens' TextCursor String

Lens for the text that is selected. Empty if nothing is selected.

#_after Source

_after :: Lens' TextCursor String

Lens for the text after the selection. Empty if the cursor or selection reaches the end.

#_all Source

_all :: Traversal' TextCursor String

Lens for traversing/setting all three fields.

#atStart Source

atStart :: TextCursor -> Boolean

Test whether the cursor or selection touches the start.

#atEnd Source

atEnd :: TextCursor -> Boolean

Test whether the cursor or selection reaches the end.

#allSelected Source

allSelected :: TextCursor -> Boolean

Test whether the cursor has selected the whole field.

#isCursor Source

isCursor :: TextCursor -> Boolean

Test whether the selection is collapsed, i.e. acts like a cursor.

#cursorAtStart Source

cursorAtStart :: TextCursor -> Boolean

Test whether the cursor is at the start with no selection.

#cursorAtEnd Source

cursorAtEnd :: TextCursor -> Boolean

Test whether the cursor is at the end with no selection.

#isSelection Source

isSelection :: TextCursor -> Boolean

Test whether some text is selected.

#selectionAtStart Source

selectionAtStart :: TextCursor -> Boolean

Test whether there is a selection that starts at the beginning.

#selectionAtEnd Source

selectionAtEnd :: TextCursor -> Boolean

Test whether there is a selection that reaches the end.

#selectAll Source

selectAll :: TextCursor -> TextCursor

Select all of the text in a field.

Note: selection direction is not specified.

#placeCursorAtStart Source

placeCursorAtStart :: TextCursor -> TextCursor

Place the cursor to the start of a field, preserving the overall text content.

#placeCursorAtEnd Source

placeCursorAtEnd :: TextCursor -> TextCursor

Place the cursor to the end of a field, preserving the overall text content.

#modifySelected Source

modifySelected :: (String -> String) -> TextCursor -> TextCursor

Modify just the selected region with an endomorphism.

#modifyAll Source

modifyAll :: (String -> String) -> TextCursor -> TextCursor

Map all three regions of the TextCursor with an endomorphism, performing a replacement or other transformation such as normalization.

#appendl Source

appendl :: String -> TextCursor -> TextCursor

Prepend a string, on the left.

#appendr Source

appendr :: TextCursor -> String -> TextCursor

Append a string, on the right.

#insert Source

insert :: String -> TextCursor -> TextCursor

Insert a string at the cursor position. If text is selected, the insertion will be part of the selection. Otherwise it is inserted before the cursor.