Members Interface
Interface for a text node.
For more information about our API support guarantees, see here.
This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.
Signature
/** @sealed */
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. |
| onCharactersChanged(callback) | Alpha | () => void | Subscribe to shallow character-level changes on this text node — inserts and removes only. |
| 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