Example #1
0
 public static void SelectHeader(this TextEditor editor, bool next)
 {
     var start = editor.SelectionStart + (next ? editor.SelectionLength : 0);
     var options = RegexOptions.Multiline | (next ? RegexOptions.None : RegexOptions.RightToLeft);
     var regex = new Regex("^#{1,6}[^#].*", options);
     var match = regex.Match(editor.Text, start);
     if (!match.Success)
     {
         Notify.Beep();
         return;
     }
     editor.Select(match.Index, match.Length);
     var loc = editor.Document.GetLocation(match.Index);
     editor.ScrollTo(loc.Line, loc.Column);
 }
Example #2
0
        public static bool Replace(this TextEditor editor, Regex find, string replace)
        {
            try
            {
                var input = editor.Text.Substring(editor.SelectionStart, editor.SelectionLength);
                var match = find.Match(input);
                var replaced = false;
                if (match.Success && match.Index == 0 && match.Length == input.Length)
                {
                    var replaceWith = match.Result(replace);
                    editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, replaceWith);
                    replaced = true;
                }

                if (!editor.Find(find) && !replaced) Notify.Beep();
                return replaced;
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return false;
            }
        }
Example #3
0
 public static bool ErrorBeep()
 {
     Notify.Beep();
     return false;
 }