Members Interface
Interface for a text node.
For more information about our API support guarantees, see here.
Signature
interface Members
Remarks
The string is broken up into substrings which are referred to as 'characters'. Unlike with JavaScript strings, all indexes are by character, not UTF-16 code unit. This avoids the problem JavaScript where it can split UTF-16 surrogate pairs producing invalid strings, and avoids the issue where indexing a string and iterating it segment the string differently. This does NOT mean the characters correspond to user perceived characters (like grapheme clusters try to do): applications will likely want to include higher level segmentation logic which might differ between operations like delete (which often operates on something in between unicode code points and grapheme clusters) and navigation/selection (which typically uses grapheme clusters).
Methods
| Method | Alerts | Return Type | Description |
|---|---|---|---|
| characterCount() | Alpha | number | Gets the number of characters currently in the text. |
| characters() | Alpha | Iterable<string> | Gets an iterable over the characters currently in the text. |
| charactersCopy() | Alpha | string[] | Optimized way to get a copy of the characters() in an array. |
| fullString() | Alpha | string | Copy the content of this node into a string. |
| insertAt(index, additionalCharacters) | Alpha | void | Insert a range of characters into the string based on character index. |
| removeRange(startIndex, endIndex) | Alpha | void | Remove a range from a string based on character index. See removeRange(start, end) for more details on the behavior. |
Method Details
characterCount
Gets the number of characters currently in the text.
For more information about our API support guarantees, see here.
Signature
characterCount(): number;
Remarks
The length of characters(). This is not the length of the string returned by fullString(), as that string may contain characters which are made up of multiple UTF-16 code units.
Returns
Return type: number
characters
Gets an iterable over the characters currently in the text.
For more information about our API support guarantees, see here.
Signature
characters(): Iterable<string>;
Remarks
This iterator matches the behavior of TreeArrayNode with respect to edits during iteration.
Returns
Return type: Iterable<string>
charactersCopy
Optimized way to get a copy of the characters() in an array.
For more information about our API support guarantees, see here.
Signature
charactersCopy(): string[];
Returns
Return type: string[]
fullString
Copy the content of this node into a string.
For more information about our API support guarantees, see here.
Signature
fullString(): string;
Returns
Return type: string
insertAt
Insert a range of characters into the string based on character index.
For more information about our API support guarantees, see here.
Signature
insertAt(index: number, additionalCharacters: string): void;
Remarks
See insertAt(index, value) for more details on the behavior. See fromString(value) for how the additionalCharacters string is broken into characters.
Parameters
| Parameter | Type | Description |
|---|---|---|
| index | number | |
| additionalCharacters | string |
removeRange
Remove a range from a string based on character index. See removeRange(start, end) for more details on the behavior.
For more information about our API support guarantees, see here.
Signature
removeRange(startIndex: number | undefined, endIndex: number | undefined): void;
Parameters
| Parameter | Type | Description |
|---|---|---|
| startIndex | number | undefined | |
| endIndex | number | undefined |
See Also
fromString(value) for construction.
Tree for schema.