// you need to select something beforehand, but excluding start/end of line // to allow +1 and -1 for selection working right var sel = ActiveView.Selection; var text = ActiveDocument.GetText(sel); ActiveView.ShowQuickInfo(text); sleep(3000); var ptEnd = sel.end; sel.end = ptEnd; ActiveDocument.BeginUndoGroup(); sel.left -= 1; sel.right += 1; ActiveView.Select(sel); Output().writeln(ActiveDocument.GetText(sel)); sleep(1500); sel.left += 1; sel.right -= 1; ActiveView.Select(sel); ActiveDocument.ReplaceText(sel.start, "New Text", sel.end, HE_ACTION_UNKNOWN); sleep(1500); ActiveDocument.ReplaceText(sel.start, text, sel.end, HE_ACTION_UNKNOWN); sleep(1500); ActiveDocument.InsertText(sel.start, "Inserted Text", sel.end, HE_ACTION_UNKNOWN); sleep(1500); ActiveDocument.DeleteText(sel, HE_ACTION_UNKNOWN); sleep(1500); ActiveDocument.FlushUndoGroup();