private void UpdateCurrentState(string replacementText, ITextSelection selection, SnapshotSpan activeSpan) { var snapshot = activeSpan.Snapshot; var selectionSpan = selection.GetSnapshotSpansOnBuffer(snapshot.TextBuffer).Single(); var start = selectionSpan.Start.TranslateTo(snapshot, PointTrackingMode.Positive).Position - activeSpan.Start.Position; var end = selectionSpan.End.TranslateTo(snapshot, PointTrackingMode.Positive).Position - activeSpan.Start.Position; this.currentState = new ActiveSpanState() { ReplacementText = replacementText, SelectionAnchorPoint = selection.IsReversed ? end : start, SelectionActivePoint = selection.IsReversed ? start : end }; }