public void ConvertSpacesToTabs()
{
if (_Document != null)
{
_Document.StartUndoCapture();
var spaces = new string(' ', _TabSize);
// Iterate all rows and convert tabs to spaces.
for (int count = 0; count < _Document.Count; count++)
{
Row row = _Document[count];
string rowText = row.Text;
string newText = rowText.Replace(spaces, "\t");
// If this has made a change to the row, update it.
if (newText != rowText)
{
_Document.DeleteRange(new TextRange(0, count, rowText.Length - 1, count));
_Document.InsertText(newText, 0, count, true);
}
}
_Document.EndUndoCapture();
}
}