private string GetSelection()
{
var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd;
var start = Math.Min(selectionStart, selectionEnd);
var end = Math.Max(selectionStart, selectionEnd);
if (start == end || (TextDocument?.TextLength ?? 0) < end)
{
return "";
}
return TextDocument.GetText(start, end - start);
}