Grouping Undo Steps with TX Text Control
TX Text Control manages undo history through snapshots and message queues. Applying multiple formatting changes via the Selection object registers as one undo step. For grouped operations, a temporary ServerTextControl processes edits offline and reloads them as a single undo entry.

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 =
TXTextControl.HorizontalAlignment.Center;
// 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,
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// create a temporary ServerTextControl to manipulate the selection
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
tx.Create();
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
textControl1.Selection.Load(data,
TXTextControl.BinaryStreamType.InternalUnicodeFormat);Related Posts
New Text Control HTML5 Ad Campaign
Text Control previewed its 2015 international print advertising campaign for the HTML5 rich text editor component. The campaign highlights the browser-based WYSIWYG editing capability of TX Text…
Windows FormsGetting StartedTutorial
Windows Forms Tutorial: Create Your First Windows Forms C# Application
This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.
How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#
Mail merge is the process of merging data, such as Json or IEnumerable objects, into a template document, such as a DOC or DOCX file. This tutorial is a walkthrough of the steps necessary to…
Creating an Angular Document Editor Application with a Node.js WebSocket Server
This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.
Adding SVG Watermarks to Documents
This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.
