toptensoftware / RichTextKit

Rich text rendering for SkiaSharp
Other
366 stars 73 forks source link

Added Extract And ReplaceText styled text to TextDocument + small mistakes fixes #79

Closed dbriard closed 1 year ago

dbriard commented 1 year ago

This PR is about adding two useful methods to TextDocument:

public StyledText Extract(TextRange range)
public void ReplaceText(ITextDocumentView view, TextRange range, StyledText styledText, EditSemantics semantics)

The first one allow to extract a range of the document as StyledText, the paragraph separators are replaced by new lines The second one is an additional ReplaceText that take a styledText directly in input, the new lines are replaced by paragraph separator.

I need those two methods in order to build a RichTextBox control, to apply a style to a range of text. Basically to update a range of rich text, I call extract to retrieve a styled text of the selection, then I modify the styles in this StyledText (or a copy of it), and finally I call ReplaceText to update the document.

I also fixed a few mistakes I've seen in the code, a null test on the wrong variable, and missing halo test in IStyleExtensions.

Last things, I wasn't able to compile the project as nullable was no available in c# 7.3 to I updated to c# 8 as advised by the compiler, please tell me if that is ok for you?