Prose.TextWithCaret

References
Represents a string with caret location and block selection. This is useful for mimicking text area inputs that are not tied to specific controls.

All positions (Caret, Block and the block bounds) are measured in grapheme clusters, not char code units. The text is segmented into complete grapheme runs (base character plus any combining marks, and whole surrogate pairs) via Prose.Graphemes, so the caret can never land inside a cluster and no edit can split one into invalid UTF-16.

Constructors

TextWithCaret

#
public TextWithCaret(
text,
The text content.
caret,
Caret position, measured in grapheme clusters.
block
Selection length, measured in grapheme clusters (signed, relative to the caret).
)

TextWithCaret

#
public TextWithCaret(
text
)

Properties

Block

#
Gets the length of the selection block (in grapheme clusters), starting at the caret.
public int Block { get; }

BlockEnd

#
Gets the index of the right edge of the block.
public int BlockEnd { get; }

BlockStart

#
Gets the index of the left edge of the block.
public int BlockStart { get; }

Caret

#
Gets the position of the caret, measured in grapheme clusters.
public int Caret { get; }

Empty

#
public static Prose.TextWithCaret Empty { get; }

IsEmpty

#
Gets whether the Text field is null or empty.
public bool IsEmpty { get; }

Length

#
Gets the number of grapheme clusters in the text.
public int Length { get; }

SelectedText

#
Gets the currently selected text.
public string SelectedText { get; }

Text

#
Gets the string inside this instance.
public string Text { get; }

Methods

ControlCaretLeft

#
Perform the default caret+block modification based on a COMMAND+LEFT arrow key press.
public Prose.TextWithCaret ControlCaretLeft()

ControlCaretRight

#
Perform the default caret+block modification based on a COMMAND+Right arrow key press.
public Prose.TextWithCaret ControlCaretRight()

DeleteAfter

#
Delete either the block or, if there is no block, the grapheme after the caret.
public Prose.TextWithCaret DeleteAfter()

DeleteBefore

#
Delete either the block or, if there is no block, the grapheme before the caret.
public Prose.TextWithCaret DeleteBefore()

DeleteBlock

#
Delete the block, if any.
public Prose.TextWithCaret DeleteBlock()

Equals

#
public override bool Equals(
obj
)
Object.Equals

Equals

#
public bool Equals()

GetHashCode

#
public override int GetHashCode()

HandleKeyDown

#
Handle a key press, additionally reporting when the key asks to leave this text altogether (see Prose.CaretDeparture). A departing key never edits the text; whether it counts as handled depends on the key: the four editing keys always do - a text context owns them even when it cannot act, and letting them bubble would trigger shortcuts elsewhere - while up and down stay unhandled, so hosts which don't accept the departure keep their existing behaviour.
public Prose.TextWithCaret HandleKeyDown(
KeyEventArgs
e,
departure
)

HandleKeyDown

#
public Prose.TextWithCaret HandleKeyDown(
KeyEventArgs
e
)

Insert

#
Replace the block with a text fragment, or insert the fragment at the caret.
public Prose.TextWithCaret Insert(
segment,
Text to insert.
adjust = true,
If true, the caret is moved to the end of the inserted segment.
select = false
If true, the selection block covers the inserted segment.
)

IsCharacterInBlock

#
Gets whether the grapheme at the given index is inside the selection.
public bool IsCharacterInBlock(
characterIndex
)

IsPositionInBlock

#
Gets whether the given caret position is inside the selection. This is true even if the block length is zero.
public bool IsPositionInBlock(
caretPosition
)

MoveCaret

#
Move the caret left or right.
public Prose.TextWithCaret MoveCaret(
steps = 1,
clearBlock = true
)

MoveCaretLeft

#
Perform the default caret+block modification based on a LEFT arrow key press.
public Prose.TextWithCaret MoveCaretLeft()

MoveCaretLeft

#
Move the caret to the left, with default behaviour based on modifier keys.
public Prose.TextWithCaret MoveCaretLeft(
Keys
modifiers
)
Modified text or this text if the caret could not be moved.

MoveCaretRight

#
Perform the default caret+block modification based on a Right arrow key press.
public Prose.TextWithCaret MoveCaretRight()

MoveCaretRight

#
Move the caret to the right, with default behaviour based on modifier keys.
public Prose.TextWithCaret MoveCaretRight(
Keys
modifiers
)
Modified text or this text if the caret could not be moved.

ReplaceBlock

#
Replace the contents of the selected block with a different text fragment. If there is no selected block, this method does nothing.
public Prose.TextWithCaret ReplaceBlock(
segment,
Text to insert.
adjust = true,
If true, the caret is moved to the end of the inserted segment.
select = false
If true, the selection block covers the inserted segment.
)

SelectAll

#
Select the entire text.
public Prose.TextWithCaret SelectAll(
caretAtStart
)

SelectWordAt

#
Select the word surrounding a caret position. A 'word' here is a run of graphemes which all classify the same way (letters and digits, whitespace, symbols), i.e. exactly the runs the by-word caret jumps step over.

The caret ends up at the end of the run, where typing is expected to continue, with the block reaching back to its start.

public Prose.TextWithCaret SelectWordAt(
position
Caret position to expand from, in grapheme clusters.
)

ShiftCaretLeft

#
Perform the default caret+block modification based on a LEFT+SHIFT arrow key press.
public Prose.TextWithCaret ShiftCaretLeft()

ShiftCaretRight

#
Perform the default caret+block modification based on a RIGHT+SHIFT arrow key press.
public Prose.TextWithCaret ShiftCaretRight()

ShiftControlCaretLeft

#
Perform the default caret+block modification based on a LEFT+SHIFT arrow key press.
public Prose.TextWithCaret ShiftControlCaretLeft()

ShiftControlCaretRight

#
Perform the default caret+block modification based on a LEFT+SHIFT arrow key press.
public Prose.TextWithCaret ShiftControlCaretRight()

ToString

#
public override string ToString()
Object.ToString

WithBlock

#
Modify the block of this text.
public Prose.TextWithCaret WithBlock(
block = 0
)

WithCaret

#
Set the caret of this text.
public Prose.TextWithCaret WithCaret(
caret
)

WithCaretAtEnd

#
Move the caret to the end of this text.
public Prose.TextWithCaret WithCaretAtEnd()

WithCaretAtStart

#
Move the caret to the start of this text.
public Prose.TextWithCaret WithCaretAtStart()

Operators