public void ChangeSelection(SelectionPosition position) { SourceEditor.Select( position == SelectionPosition.BodyStart ? 0 : position == SelectionPosition.BodyEnd ? SourceEditor.TextLength : 0, 0); }
/// <summary> /// If the specified markers exist in the editor text, /// delete the first instance of each and position the /// selection at the markers. /// </summary> public bool SelectAndDelete(string startMarker, string endMarker) { string html = SourceEditor.Text; int startIndex, startLen; FindMarker(html, startMarker, out startIndex, out startLen); int endIndex, endLen; FindMarker(html, endMarker, out endIndex, out endLen); if (startIndex > endIndex) { Trace.Fail("Selection startIndex is before endIndex--this should never happen"); int temp = startIndex; startIndex = endIndex; endIndex = temp; temp = startLen; startLen = endLen; endLen = temp; } if (endIndex >= 0) { html = html.Substring(0, endIndex) + html.Substring(endIndex + endLen); } if (startIndex >= 0) { html = html.Substring(0, startIndex) + html.Substring(startIndex + startLen); if (endIndex >= 0) { endIndex -= startLen; } } SourceEditor.Text = html; if (startIndex >= 0) { SourceEditor.Select(startIndex, endIndex - startIndex); SourceEditor.ScrollToCaret(); return(true); } return(false); }