How to use Run or TextBlock instead of pure text in SyntaxEditor

SyntaxEditor for WPF Forum

Posted 2 months ago by Joey Lu
Version: 24.1.2
Avatar

I watch source code of TextDocument, it provides many methods like SetText and AppendText. It looks like only accept pure text.

I want some decoration and operation when I select a word or a sentence.

For example, here is a url: www.abc.com, I would like to it has underline, font weight is bold, when i hold left Ctrl and click, it will open a browser and redirect to the page. Also I would like the url holding other important infomation that I will use when I do something else.

How do I achieve that? Or can I use Run or TextBlock instead of pure text in SyntaxEditor?

Kinds regards,

Joey Lu

[Modified 2 months ago]

Comments (1)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

SyntaxEditor only edits pure text documents, similar to the Visual Studio code editor.  It uses a syntax language's lexer to provide tokenization/classification of text and syntax highlighting.

SyntaxEditor also has some mechanisms to "tag" ranges of text and apply special formatting to them.  URLs are a kind of thing that could possibly be tagged if you are watching the text for a URL-like pattern.  Then you could apply the underline and bold appearance to the tagged range.  While we don't have a sample for URL recognition, many of the Adornments-related QuickStart samples show the general concept of tagging ranges and applying a highlighting style over those ranges.  For instance the "Adornments 3 - Custom Decorator" sample tags the text "Actipro" when found.

As for watching for clicks, using an IEditorViewPointerInputEventSink would allow your syntax language to be notified of clicks and you could check for a Ctrl modifier in the event sink handler.  More info on event sinks is in the product documentation.  If you look at the "Go To Definition" sample (under the .NET Languages Add-on QuickStarts category) you will see an example where the Ctrl key is watched to look for tags under the pointer.


Actipro Software Support

The latest build of this product (v24.1.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.