Environmental.NewLine and TextRanges

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Erik Pepping - RADVenture B.V
Version: 4.0.0260
Avatar
Environmental.NewLine and TextRanges

In my project i have a class that uses System.String and StringBuilder for document creation. This class also keeps a small list of indexes to identify location of certain tokens.The indexes are calculated using string.IndexOf

What I've noticed is that in ActiPro document, a new Line uses 1 char position
instead of 2 chars (\n\r) which a string with Environmental.NewLine uses.

When I try to locate the caret offset using my original TextRanges,
then it places the caret in a different position than expected.

Note: My workaround was to adapt my classes to start counting how many NewLines
and have a separate TextRange where the newlines are substracted.
I would like to remove this extra calculation in the future , therefore the question.


Is there any way to configure the editor/document to "use" 2 chars so i can use the "same" TextRanges?

Comments (3)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sorry but no, SyntaxEditor uses a single line feed internally for denoting line terminators. This is to make parsing much faster since otherwise, we would have to potentially be checking for 1 or 2 characters, and either carriage return/line feed all over the place. Basically it would make parsing much more difficult and time consuming in a number of areas.

Properties like Document.Text give back the normal \r\n line ends though and Document.GetText allows you to get a different version of the line ends.


Actipro Software Support

Posted 12 years ago by Erik Pepping - RADVenture B.V
Avatar
It's OK, I've asked just in case the behavior was already there and i was missing it.

Maybe it's a good tip to add this info to the Documentation since it took me some hours until i found out that the NewLines where the reason for my "offset" difference..

Thanks for the quick reply.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Good idea, perhaps we could add something in the Getting Started topic that explains this.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 10 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.