ITextChange does not update its PositionToOffset()

SyntaxEditor for WPF Forum

Posted 3 years ago by Daniel Constantin - ModuleWorks GmbH
Version: 19.1.0687
Avatar

Hi,

I am trying to do multiple replacements inside one undoable action.

For this I am using the ITextChange from Document.CurrentSnapshot.CreateTextChange().

Before the actual replaces I search my strings and store their positions inside a list of TextPositionRange.

If I replace my strings with some string having the same number of characters, it will work. If I replace with string.Empty, it will replace in the old positions so the replacing will be wrong. Somehow I need to update the ITextChange so the PositionToOffset() to get me the correct offsets. The offsets seems to change after each replace the ITextChange is doing.

Kind regards,

Daniel

Comments (1)

Answer - Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Daniel,

If you have a list of replace operations in a single text change, there are a couple ways to approach this to handle changing offsets.

1) Add the change operations in reverse sequential order.  You start making your change operations at the end of the document first and move back towards the document start.  That way the change operations being made never affect the offsets of change operations that haven't yet been added.

or

2) If you want to go in forward order (document start towards end) of adding change operations, set the TextChangeOptions.OffsetDelta property to TextChangeOffsetDelta.SequentialOnly, and use that options object when you call CreateTextChange.  One of the overloads takes an options object.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.