private void MoveSelectedLines(string section) { _rtb.SuspendPainting(); var padded = GetPaddedText(Text); var i = _rtb.SelectionStart + 1; var j = i + Math.Max(0, _rtb.SelectionLength - 1); var cutIndex = Helper.GetLineStart(padded, i); var k = Helper.GetLineEnd(padded, j); var copyLength = k - cutIndex; var cutLength = copyLength + (k < padded.Length ? 1 : 0); var copiedText = padded.Substring(cutIndex, copyLength); _rtb.Select(cutIndex - 1, cutLength); _rtb.SelectedText = ""; padded = GetPaddedText(Text); var insertIndex = GetAppendIndex(padded, section); if (insertIndex == -1) { _rtb.SelectedText = copiedText + "\n"; } else { _rtb.Select(insertIndex - 1, 0); var lengthBefore = _rtb.TextLength; _rtb.SelectedText = "\n" + copiedText; _rtb.Select(cutIndex - 1 + (insertIndex < cutIndex ? _rtb.TextLength - lengthBefore : 0), 0); } _rtb.ResumePainting(); }