Prose.TextWithCaret
ReferencesRepresents 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
#Properties
Methods
ControlCaretLeft
#Perform the default caret+block modification based on a COMMAND+LEFT arrow key press.
ControlCaretRight
#Perform the default caret+block modification based on a COMMAND+Right arrow key press.
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.
Parameters:
| e (KeyEventArgs) | |
| departure (out Prose.CaretDeparture) |
IsCharacterInBlock
#Gets whether the grapheme at the given index is inside the selection.
Parameters:
| characterIndex (int) |
IsPositionInBlock
#Gets whether the given caret position is inside the selection. This is true even if the block length is zero.
Parameters:
| caretPosition (int) |
MoveCaretLeft
#Move the caret to the left, with default behaviour based on modifier keys.
Parameters:
| modifiers (Keys) |
Returns: Modified text or this text if the caret could not be moved.
MoveCaretRight
#Move the caret to the right, with default behaviour based on modifier keys.
Parameters:
| modifiers (Keys) |
Returns: 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.
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.
Parameters:
| position (int) | Caret position to expand from, in grapheme clusters. |
ShiftCaretRight
#Perform the default caret+block modification based on a RIGHT+SHIFT arrow key press.
ShiftControlCaretLeft
#Perform the default caret+block modification based on a LEFT+SHIFT arrow key press.
ShiftControlCaretRight
#Perform the default caret+block modification based on a LEFT+SHIFT arrow key press.
Operators
| Operation | Result | Description | ||
|---|---|---|---|---|
| Prose.TextWithCaret | == | Prose.TextWithCaret | bool | |
| Prose.TextWithCaret | != | Prose.TextWithCaret | bool | |