Thank you for the sample via a support ticket. In that sample, you were handling the SyntaxEditor.DocumentTextChanged event and were applying an AutoComplete text change in response to it. Right after calling the ITextChange.Apply() method, you set the editor.ActiveView.Selection.CaretOffset to a value.
In v21.1.2, we had to make a change to ensure that SyntaxEditor.DocumentTextChanged events fire in proper version order. The issue in prior versions was this kind of scenario:
- Some text change occurs, causing snapshot version 2.
- The SyntaxEditor.DocumentTextChanged event is raised for version 2 and some watchers (like for selection changes, etc.) start handling it.
- Code that provides auto-completion (or other things like auto-correct, auto-indent) also handles the SyntaxEditor.DocumentTextChanged event and applies another text change to further alter the original text change's text results. This causes snapshot version 3.
- The SyntaxEditor.DocumentTextChanged event is immediately raised for version 3 and all watchers handle version 3's event completely.
- Now that the auto-completion logic's Apply() method returns, any remaining watchers of the DocumentTextChanged event that have not yet handled the event that was raised for version 2 get that event.
- At this point, some event watchers will have received version 3's event before version 2 and things like outlining or selection could get out of whack.
The change we made in v21.1.2 was to ensure that SyntaxEditor.DocumentTextChanged always fires events in version order. If it's in the middle of raising snapshot version 2's event, it will queue up snapshot version 3's event to fire only after ALL handlers of the event have first seen version 2's event.
In your scenario, this means that the view is not yet aware of the new snapshot created by your auto-complete, even though it returned from that text change's Apply() method. Thus trying to set the view's selection with editor.ActiveView.Selection.CaretOffset based on the results of the auto-complete snapshot (which the view doesn't yet know about) will fail to work properly.
Instead of setting the CaretOffset property, you can do this kind of thing before your auto-completion's Apply() call, and it will work:
yourAutoCompleteChange.PostSelectionPositionRanges = TextPositionRange.CreateCollection(new TextPositionRange(0, 5, 0, 5), isBlock: false);
That allows you to specify what the resulting selection should be after the text change is applied. There it's saying it should be a zero-length selection at position (0, 5).
I hope that helps explain why the event logic change was necessary and how to alter your selection code appropriately.