
1.On that note, I would recommend setting it before you call ITextChange.Apply() though. Setting it after may work in this particular scenario since the changed event is getting buffered, but in normal circumstances when there isn't already a text change being processed, setting PostSelectionPositionRanges after Apply() would be too late.
According to you say, I need to set the PostSelectionPositionRanges property before calling ITextChange.Apply().
But as I mentioned earlier, the data for cursor repositioning may be an offset. I need to convert him to position. I need the latest snapshot to convert the offset to the correct position.
So in this case, I can only call ITextChange.Apply() first. After getting the latest snapshot, the converted position can be obtained to reposition the cursor.
2.About the scope of influence
After this update, I temporarily found that two functions were abnormal.
(1)One is the formatting function, which I inherited from TextFormatter. In the implementation of the Format method, there is a method to reposition the cursor (reposition the cursor by setting Active.Selection.CaretOffset).
(2)The other is to insert comment snippet. This is achieved by subscribing to the SyntaxEditor.DocumentTextChanged event, and the cursor positioning fails.
In the method implemented by IEditorDocumentTextChangeEventSink. Is working as expected.