Skip to main content
Version: v2

ISharedString Interface

Fluid object interface describing access methods on a SharedString

This API is provided for existing users, but is not recommended for new users.

To use, import via fluid-framework/legacy.

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

Signature​

export interface ISharedString extends ISharedSegmentSequence<SharedStringSegment>

Extends: ISharedSegmentSequence<SharedStringSegment>

Methods​

MethodAlertsReturn TypeDescription
annotateMarker(marker, props)BetavoidAnnotates the marker with the provided properties.
getMarkerFromId(id)BetaISegment | undefinedLooks up and returns a Marker using its id. Returns undefined if there is no marker with the provided id in this SharedString.
getText(start, end)BetastringRetrieve text from the SharedString in string format.
getTextRangeWithMarkers(start, end)Betastring
getTextWithPlaceholders(start, end)BetastringAdds spaces for markers and handles, so that position calculations account for them.
insertMarker(pos, refType, props)BetavoidInserts a marker at the position.
insertMarkerRelative(relativePos1, refType, props)BetavoidInserts a marker at a relative position.
insertText(pos, text, props)BetavoidInserts the text at the position.
insertTextRelative(relativePos1, text, props)BetavoidInserts the text at the position.
removeText(start, end)BetavoidRemoves the text in the given range.
replaceText(start, end, text, props)BetavoidReplaces a range with the provided text.
searchForMarker(startPos, markerLabel, forwards)BetaMarker | undefinedSearches a string for the nearest marker in either direction to a given start position. The search will include the start position, so markers at the start position are valid results of the search.

Method Details​

annotateMarker​

Annotates the marker with the provided properties.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

annotateMarker(marker: Marker, props: PropertySet): void;

Parameters​

ParameterTypeDescription
markerMarkerThe marker to annotate
propsPropertySetThe properties to annotate the marker with

getMarkerFromId​

Looks up and returns a Marker using its id. Returns undefined if there is no marker with the provided id in this SharedString.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

getMarkerFromId(id: string): ISegment | undefined;

Parameters​

ParameterTypeDescription
idstring

Returns​

Return type: ISegment | undefined

getText​

Retrieve text from the SharedString in string format.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

getText(start?: number, end?: number): string;

Parameters​

ParameterModifiersTypeDescription
startoptionalnumberThe starting index of the text to retrieve, or 0 if omitted.
endoptionalnumberThe ending index of the text to retrieve, or the end of the string if omitted

Returns​

The requested text content as a string.

Return type: string

getTextRangeWithMarkers​

This API is provided for existing users, but is not recommended for new users.

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

Signature​

getTextRangeWithMarkers(start: number, end: number): string;

Parameters​

ParameterTypeDescription
startnumber
endnumber

Returns​

Return type: string

getTextWithPlaceholders​

Adds spaces for markers and handles, so that position calculations account for them.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

getTextWithPlaceholders(start?: number, end?: number): string;

Parameters​

ParameterModifiersTypeDescription
startoptionalnumber
endoptionalnumber

Returns​

Return type: string

insertMarker​

Inserts a marker at the position.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void;

Parameters​

ParameterModifiersTypeDescription
posnumberThe position to insert the marker at
refTypeReferenceTypeThe reference type of the marker
propsoptionalPropertySetThe properties of the marker

insertMarkerRelative​

Inserts a marker at a relative position.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

insertMarkerRelative(relativePos1: IRelativePosition, refType: ReferenceType, props?: PropertySet): void;

Parameters​

ParameterModifiersTypeDescription
relativePos1IRelativePositionThe relative position to insert the marker at
refTypeReferenceTypeThe reference type of the marker
propsoptionalPropertySetThe properties of the marker

insertText​

Inserts the text at the position.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

insertText(pos: number, text: string, props?: PropertySet): void;

Parameters​

ParameterModifiersTypeDescription
posnumberThe position to insert the text at
textstringThe text to insert
propsoptionalPropertySetThe properties of the text

insertTextRelative​

Inserts the text at the position.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet): void;

Parameters​

ParameterModifiersTypeDescription
relativePos1IRelativePositionThe relative position to insert the text at
textstringThe text to insert
propsoptionalPropertySetThe properties of text

removeText​

Removes the text in the given range.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

removeText(start: number, end: number): void;

Parameters​

ParameterTypeDescription
startnumberThe inclusive start of the range to remove
endnumberThe exclusive end of the range to replace

Returns​

the message sent.

replaceText​

Replaces a range with the provided text.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

replaceText(start: number, end: number, text: string, props?: PropertySet): void;

Parameters​

ParameterModifiersTypeDescription
startnumberThe inclusive start of the range to replace
endnumberThe exclusive end of the range to replace
textstringThe text to replace the range with
propsoptionalPropertySetOptional. The properties of the replacement text

searchForMarker​

Searches a string for the nearest marker in either direction to a given start position. The search will include the start position, so markers at the start position are valid results of the search.

This API is provided for existing users, but is not recommended for new users.

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

Signature​

searchForMarker(startPos: number, markerLabel: string, forwards?: boolean): Marker | undefined;

Parameters​

ParameterModifiersTypeDescription
startPosnumberPosition at which to start the search
markerLabelstringLabel of the marker to search for
forwardsoptionalbooleanWhether the desired marker comes before (false) or after (true) startPos. Default true.

Returns​

Return type: Marker | undefined