@express-document-sdk / TextContentModel
Class: abstract
TextContentModel
TextContentModel is an abstract base class representing a complete piece of text content. Use this model to get or modify the text string and the style ranges applied to it.
Extended by
Accessors
characterStyleRanges
• get
characterStyleRanges(): readonly CharacterStylesRange
[]
The character styles are applied to different ranges of this text content. When setting character styles, any style properties that are not provided are reset to their defaults (contrast to applyCharacterStyles which preserves the text's existing styles for any fields not specified). When getting styles, all fields are always provided.
Note: existing fonts used in the document, returned by this getter, are not guaranteed to be ones the current user has rights to edit with. The setter only accepts the AvailableFont type which has been verified to be usable.
• set
characterStyleRanges(styles
): void
Parameters
• styles: readonly CharacterStylesRangeInput
[]
Returns
readonly CharacterStylesRange
[]
id
• get
id(): string
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
A unique identifier for this node that stays the same when the file is closed & reopened, or if the node is moved to a different part of the document.
To determine if two TextNodes are connected to the same TextContentModel,
check if both models have the same id.
Comparing two models using ===
will always fail.
Returns
string
paragraphStyleRanges
• get
paragraphStyleRanges(): readonly ParagraphStylesRange
[]
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
The styles applied to different paragraphs of this text content.
• set
paragraphStyleRanges(styles
): void
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Apply styles to different paragraphs of this text content. Any style properties that are not provided are reset to their defaults. When getting styles, all properties are always provided.
Paragraphs are separated by newline characters (\n
). The ranges specified here should align with
those boundaries. If multiple ranges provided overlap a single paragraph, the first one to overlap is applied to the
entire paragraph.
Throws
if the text content contains fonts unavailable to the current user and an ordered-list style is being applied.
Parameters
• styles: readonly ParagraphStylesRangeInput
[]
Returns
readonly ParagraphStylesRange
[]
text
• get
text(): string
The complete text string, which may span multiple ThreadedTextNode "frames" in the scenegraph.
• set
text(textContent
): void
Parameters
• textContent: string
Returns
string
Methods
appendText()
• appendText(newText
): void
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Appends a new text string to the end of the text content.
Parameters
• newText: string
The text to append.
Returns
void
Throws
if the existing text contains fonts unavailable to the current user. See hasUnavailableFonts.
applyCharacterStyles()
• applyCharacterStyles(styles
, range
?): void
Apply one or more styles to the characters in the given range, leaving any style properties that were not specified unchanged. Does not modify any styles in the text outside this range. Contrast to the characterStyleRanges setter, which specifies new style range(s) for the entire text at once, and resets any unspecified properties back to default styles.
Parameters
• styles: CharacterStylesInput
The styles to apply.
• range?: TextRange
The start and length of the character sequence to which the styles should be applied. The styles will be applied to the entire text content flow if not specified. If the specified range doesn't align well with the paragraph boundaries, the range will be expanded to cover the entire paragraphs, it overlaps.
Returns
void
applyParagraphStyles()
• applyParagraphStyles(styles
, range
?): void
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Apply one or more styles to the paragraphs in the given range, leaving any style properties that were not specified unchanged. Does not modify any styles in the text outside this range. Contrast to the paragraphStyleRanges setter, which specifies new style range(s) for the entire text at once, and resets any unspecified properties back to default styles.
Parameters
• styles: ParagraphStylesInput
The styles to apply.
• range?: TextRange
The start and length of character sequence to which the styles should be applied. If not specified the styles will be applied to the entire piece of text content flow.
Returns
void
deleteText()
• deleteText(range
): void
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Deletes a range of text from the content.
Parameters
• range: TextRange
The range of text to delete.
Returns
void
Throws
if the existing text contains fonts unavailable to the current user. See hasUnavailableFonts.
hasUnavailableFonts()
• hasUnavailableFonts(): boolean
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Returns true if this text contains any fonts unavailable to the current user. Currently, if any unavailable fonts are present, the text content cannot be modified and certain styling changes are limited as well. To remove these restrictions, you must modify the character styles to use only AvailableFonts.
Returns
boolean
insertText()
• insertText(newText
, index
, style
?): void
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Inserts a new text string into the text content at the specified index.
Parameters
• newText: string
The text to insert.
• index: number
The index at which to insert the new text.
• style?: CharacterStylesInput
| beforeInsertionPoint
| afterInsertionPoint
Style to use for the new text: either directly provides a style to use, or indicates which
existing text to match the style of. Default: beforeInsertionPoint
.
Returns
void
Throws
if the existing text contains fonts unavailable to the current user. See hasUnavailableFonts.
replaceText()
• replaceText(newText
, replaceRange
, style
?): void
IMPORTANT: This is currently experimental only and should not be used in any add-ons you will be distributing until it has been declared stable. To use it, you will first need to set the experimentalApis
flag to true
in the requirements
section of the manifest.json
.
Replaces a range of text with a new text string.
Parameters
• newText: string
The text to replace the range with.
• replaceRange: TextRange
The range of text to replace.
• style?: CharacterStylesInput
| beforeInsertionPoint
| afterInsertionPoint
| firstReplacedCharacter
Style to use for the new text: either directly provides a style to use, or indicates which
existing text to match the style of. Default: firstReplacedCharacter
.
Returns
void
Throws
if the existing text contains fonts unavailable to the current user. See hasUnavailableFonts.