Selection.TextRange Index & Length

SyntaxEditor for WPF Forum

Posted 15 years ago by Matt Bates
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
It seems there may be an issue surrounding selecting text (only tested with CSS) in the syntax editor using Selection.TextRange with a new TextRange(index, offset) object.

I have the following scenario:
  • Read a stylesheet into the system
  • Use Regex to get each rule in the stylesheet along with their indexes and length
  • Set the syntax editor text to the stylesheet
  • When I set the Selection.TextRange to a new TextRange using the index and length found using regex the selection length is a few characters to long.
I did some experimenting with this and it looks like the syntax editor doesn't count "[\n]" characters. If I remove all new line characters from the stylesheet (again with regex: Regex.Replace(cssText, "[\n]", "")) then process with regex to get the indexes and lengths selection works great.

I can send through a sample project if need be.


Comments (2)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Matt,

Actually SyntaxEditor strips out all \r characters and stores only \n internally. This is so that we consistently know there is a single line terminator character on each line. It helps with performance. When you use a number of methods to get text back out, it can easily convert back to \r\n again. So this is by design.

We're starting documentation topics now and will have a topic on line terminators to explain all this.

Instead of using an external regex, you can use the editor view search mechanism. I don't think it's in the current alpha however we hope to have a new alpha out in the next several days that has all the find/replace functionality that we blogged about. Check out the blog for details on that. It fully supports regex finds, etc. and will select results.

Actipro Software Support

Posted 15 years ago by Matt Bates
Thanks for the quick reply. Good to hear that some doc's are on the way, looking forward to the next release.
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.