The undo and redo history is a very complex internal process that utilizes snapshots, message queues and internal grouping mechanisms to provide a smooth undo experience. For example, while typing, a single undo step is not the single key press, but the complete text until a new action such as a specific formatting is applied.

Internally, complex and highly optimized history lists are generated to save memory and keep up the performance.

In case, the Selection object and its direct properties should be manipulated, these changes are counted as 1 undo step. The following code shows how to apply various formatting options to the current selection with only 1 undo step in the history:

TXTextControl.Selection mySelection = new TXTextControl.Selection();

mySelection.Bold = true;
mySelection.ListFormat.Type = TXTextControl.ListType.Numbered;
mySelection.ParagraphFormat.Alignment =

// 1 undo step
textControl1.Selection = mySelection;

In case, you want to group several, more complex undo steps in one, you can use a temporary, invisible ServerTextControl to manipulate the selection or the complete document. The following code shows how to insert and format a table into the current selection:

byte[] data;

// save the current selection in a byte array
textControl1.Selection.Save(out data,

// create a temporary ServerTextControl to manipulate the selection
using (TXTextControl.ServerTextControl tx =
    new TXTextControl.ServerTextControl())
    tx.Load(data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

    // do 'something' here
    tx.Tables.Add(5, 5, 13);

    foreach (TXTextControl.TableCell cell in tx.Tables.GetItem(13).Cells)
        cell.CellFormat.LeftBorderWidth = 1;
        cell.Text = "new text";

    // save out the manipulated selection
    tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

// load the manipulated selection  back into the TextControl
// this 'loading' will be 1 undo step