Skip to main content

SubDocument.GetTextSpanAsync(Int32, Int32, CancellationToken) Method

Gets the text span at the specified position.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v24.2.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<TextSpan> GetTextSpanAsync(
    int startPosition,
    int length,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
startPosition Int32

A start position of the span.

length Int32

A length of the span.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<TextSpan>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is the text span.

Remarks

Call the ChangePropertiesAsync(Action<CharacterProperties>, CancellationToken) method to change properties of the text span’s characters.

<DxRichEdit @ref="richEdit" CssClass="w-100 ch-720"/>

@code {
    DxRichEdit richEdit;
    async Task InitializeDocument() {
        Document documentAPI = richEdit.DocumentAPI;
        documentAPI.BeginUpdate();
        documentAPI.BeginTransaction();
        await CreateBodyParagraph(documentAPI);
        await documentAPI.EndTransaction();
        documentAPI.EndUpdate();
    }
    async Task CreateBodyParagraph(Document documentAPI) {
        Paragraph bodyParagraph = await documentAPI.Paragraphs.CreateAsync(0);
        await bodyParagraph.ChangePropertiesAsync(properties => {
            properties.FirstLineIndentType = FirstLineIndentType.Indented;
            properties.FirstLineIndent = 500;
        });
        string bodyParagraphText = "Albert Einstein (14 March 1879 - 18 April 1955) was a German-born theoretical physicist, widely acknowledged to be one of the greatest physicists of all time. Einstein is known for developing the theory of relativity, but he also made important contributions to the development of the theory of quantum mechanics.";
        TextSpan bodyParagraphTextSpan = await documentAPI.AddTextAsync(0, bodyParagraphText);
        await bodyParagraphTextSpan.ChangePropertiesAsync(properties => {
            properties.FontName = "Segoe UI";
            properties.FontSize = 12;
        });
        TextSpan boldTextSpan = await documentAPI.GetTextSpanAsync(0, 15);
        await boldTextSpan.ChangePropertiesAsync(properties => { properties.FontBold = true; });
        TextSpan italicTextSpan = await documentAPI.GetTextSpanAsync(16, 31);
        await italicTextSpan.ChangePropertiesAsync(properties => { properties.FontItalic = true; });
        await documentAPI.Hyperlinks.CreateAsync(bodyParagraphText.IndexOf("quantum mechanics"), "quantum mechanics".Length, url: "https://en.wikipedia.org/wiki/Quantum_mechanics");
        await documentAPI.Hyperlinks.CreateAsync(bodyParagraphText.IndexOf("theory of relativity"), "theory of relativity".Length, url: "https://en.wikipedia.org/wiki/Theory_of_relativity");
        await documentAPI.Hyperlinks.CreateAsync(bodyParagraphText.IndexOf("theoretical physicist"), "theoretical physicist".Length, url: "https://en.wikipedia.org/wiki/Theoretical_physics");
    }
}

Run Demo: Document API

See Also