I am looking to group a set of changes together so they can be undone atomically, reading though other posts this is acomplished via the ITextChange.
Using this mechanisum I have managed to group changes, but the behaviour of the interface makes it somewhat tricky to use.
From what I can gather ITextChange groups the changes and applies them in the order they were added.
So if the document is
and you intend to perform 2 changes, replacing '1' for 'aa' and '3' for 'bb'
you would expect to do something like
myTextChange.Replace(start:1, length:1, insertString:"aa");
myTextChange.Replace(start:3, length:1, insertString:"bb");
but these get applied producing (which makes sense, but makes producing the second replace rather tricky in more general cases)
01234 -> 0aa234 ->0aabb34
I've tried translating offsets to the ITextChange.Snapshot assuming the snapshot would contain the changes (but snapshot does not change).
In my case I have solved the problem by coping all the changes out, ordering them by offset and building a new ITextChange, then applying that. This works for us as our changes do not overlap, but its difficult to see how to use this interface effectivley?