TextSnapshotRange swaps StartOffset/EndOffset?

SyntaxEditor for WPF Forum

Posted 10 years ago by Daniel Navarro
Version: 9.1.0502
Platform: .NET 3.5
Environment: Windows XP (64-bit)
Avatar
I'm keeping a list TextSnapshotRange (compilation errors in an DSL), but I want the caret to end up sometimes at the beginning, and sometimes at the end of the range when its selected.

The thing is when I create a new TextSnapshotRange from the TextRange (to keep track of versions) the order of StartOffset/EndOffset are always sorted! (it doesn't keep the original direction of the range).

Let me explain this with an example:

// r1 and r2 are two similar ranges, but in different direction

TextRange r1 = new TextRange(start, end);
TextRange r2 = new TextRange(end, start);

// r1 != r2, but when I convert them to a TextSnapshotRange ...

TextSnapshotRange sr1 = new TextSnapshotRange(Snapshot, r1);
TextSnapshotRange sr2 = new TextSnapshotRange(Snapshot, r2);

// then sr1 == sr2 (it doesn't keep the direction of the selection range)

And I can't find a workaround because all TextSnapshotRange properties are read only, so I can't swap the StartOffset and the EndOffset myself when the direction of the range was backwards.

Thanks.

Please let me know if I didn't explain myself clearly :)

[Modified at 07/22/2009 03:13 PM]

Comments (2)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Daniel,

That is correct and is by design. Note the summary comment on TextSnapshotRange indicates it is normalized (start before end):
"Represents a zero-based range of two normalized offset values within a certain ITextSnapshot."

If you have the requirements you indicated, I would recommend you perhaps make another struct that takes a TextSnapshotRange and a boolean that would indicate if the range should be inverted or not. Then store that struct instead.


Actipro Software Support

Posted 10 years ago by Daniel Navarro
Avatar
Ok, I missed that bit. Will do.

Thanks for your response.
The latest build of this product (v2019.1 build 0683) 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.