public void SaveSelection()
 {
     SelectionUndoRecord selection = new SelectionUndoRecord(textEdit);
     selection.Next = records;
     records = selection;
 }
            public void CloseGroup()
            {
                if (groupStart == null)
                {
                    Debug.Assert(false);
                    throw new InvalidOperationException();
                }

                if (groupStart == records)
                {
                    // delete empty undo group to eliminate no-op entries on user's undo stack
                    records = records.Next;
                    return;
                }

                if (clearRedo)
                {
                    textEdit.redo = null;
                }

                SelectionUndoRecord selection = new SelectionUndoRecord(textEdit);
                selection.Next = records;
                records = selection;

                GroupEndUndoRecord end = new GroupEndUndoRecord(groupStart);
                end.Next = records;
                records = end;

                groupStart = null;
            }