Skip to main content

Members Interface

Interface for a text node.

This API is provided as an alpha preview and may change without notice.

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

MethodAlertsReturn TypeDescription
characterCount()AlphanumberGets the number of characters currently in the text.
characters()AlphaIterable<string>Gets an iterable over the characters currently in the text.
charactersCopy()Alphastring[]Optimized way to get a copy of the characters() in an array.
fullString()AlphastringCopy the content of this node into a string.
insertAt(index, additionalCharacters)AlphavoidInsert a range of characters into the string based on character index.
removeRange(startIndex, endIndex)AlphavoidRemove 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.

This API is provided as an alpha preview and may change without notice.

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.

This API is provided as an alpha preview and may change without notice.

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.

This API is provided as an alpha preview and may change without notice.

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.

This API is provided as an alpha preview and may change without notice.

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.

This API is provided as an alpha preview and may change without notice.

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

ParameterTypeDescription
indexnumber
additionalCharactersstring

removeRange

Remove a range from a string based on character index. See removeRange(start, end) for more details on the behavior.

This API is provided as an alpha preview and may change without notice.

For more information about our API support guarantees, see here.

Signature

removeRange(startIndex: number | undefined, endIndex: number | undefined): void;

Parameters

ParameterTypeDescription
startIndexnumber | undefined
endIndexnumber | undefined

See Also

fromString(value) for construction.

Tree for schema.