This is a migrated thread and some comments may be shown as answers.

Acccess underlying text from RadSyntaxEditor

2 Answers 362 Views
SyntaxEditor
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 01 Jan 2020, 06:03 PM

Hi,

I'm working with the RadSyntaxEditor (WPF R3 2019) and loving it. It is a great control with lots of potential for our team.

 

The issue I have is simple and I feel silly having to ask something so trivial, but is there a way access the underlying text of the TextDocument? We need it to write to a stream and save the document after editing. I've tried looking in the TextDocument and TextSnapShot objects, iterating all the lines and spans, and calling all their ToString() methods, but nothing seemed to work. Is there a way to access the raw text from the rope, or even the rope itself?

 

Thank you ahead of time for your help,

Happy New Year.

Tim

2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 03 Jan 2020, 10:53 AM

Hello Tim,

Thank you for your kind words first. To access all text from the current document you can use:

            string alltext = this.syntaxEditor.Document.CurrentSnapshot.GetText();

Also you can get a particular line then get its text with:

            string lineText = this.syntaxEditor.Document.CurrentSnapshot.GetLineFromPosition(this.syntaxEditor.CaretPosition.Index).GetText();

or

 string line25Text = this.syntaxEditor.Document.CurrentSnapshot.GetLineFromLineNumber(25).GetText();

Ropes are internal structures for now. However, if certain demand requires them to be more visible we will take it into consideration. We will be glad to receive any feedback regarding the usage of this component. 

Regards,
Petar Mladenov
Progress Telerik

Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Tim
Top achievements
Rank 1
answered on 03 Jan 2020, 04:37 PM

Awesome. Thank you so much. I eventually figured this out after messing around with some of the document events. I don't know why, but I expected it to be a property for some reason.

 

 

 

Tags
SyntaxEditor
Asked by
Tim
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Tim
Top achievements
Rank 1
Share this question
or