public static void CompleteItem(SETextBox tb, IntellisenseItem item) { if (item == IntellisenseItem.IntellisenseItemEdit) { using (var form = new AssaTagTemplate()) { form.ShowDialog(); } return; } tb.SuspendLayout(); // remove old tag if any if (!string.IsNullOrEmpty(item.ActiveTagAtCursor) && tb.SelectionLength == 0) { RemoveTagAtCursor(tb); item.TypedWord = string.Empty; } // insert new tag var oldStart = tb.SelectionStart; if (item.TypedWord.Length > 0) { tb.SelectedText = item.Value.Remove(0, item.TypedWord.Length); } else { if (tb.SelectionStart > 0 && tb.Text[tb.SelectionStart - 1] == '}' && item.Value.StartsWith('\\')) { tb.SelectedText = "{" + item.Value; } else { tb.SelectedText = item.Value; } } var newStart = oldStart + item.Value.Length; // merge tags before/after var subtract = MergeTagAtCursor(tb, oldStart, true); subtract += MergeTagAtCursor(tb, newStart, false); tb.SelectionStart = newStart - subtract - item.TypedWord.Length; tb.ResumeLayout(); AddUsedTag(item.Value); }