public bool FindNext(string textToFind, Controls.FindReplaceSettings settings)
        {
            Argument.IsNotNull(() => textToFind);
            Argument.IsNotNull(() => settings);

            var regex = settings.GetRegEx(textToFind);
            var start = regex.Options.HasFlag(RegexOptions.RightToLeft) ? _textEditor.SelectionStart : _textEditor.SelectionStart + _textEditor.SelectionLength;
            var match = regex.Match(_textEditor.Text, start);

            if (!match.Success) // start again from beginning or end
            {
                match = regex.Match(_textEditor.Text, regex.Options.HasFlag(RegexOptions.RightToLeft) ? _textEditor.Text.Length : 0);
            }

            if (!match.Success)
            {
                return(false);
            }

            _textEditor.Select(match.Index, match.Length);
            var loc = _textEditor.Document.GetLocation(match.Index);

            _textEditor.ScrollTo(loc.Line, loc.Column);

            return(match.Success);
        }
        public bool Replace(string textToFind, string textToReplace, Controls.FindReplaceSettings settings)
        {
            Argument.IsNotNull(() => textToFind);
            Argument.IsNotNull(() => textToReplace);
            Argument.IsNotNull(() => settings);

            var regex = settings.GetRegEx(textToFind);
            var input = _textEditor.Text.Substring(_textEditor.SelectionStart, _textEditor.SelectionLength);
            var match = regex.Match(input);

            if (!match.Success || match.Index != 0 || match.Length != input.Length)
            {
                return(FindNext(textToFind, settings));
            }

            _textEditor.Document.Replace(_textEditor.SelectionStart, _textEditor.SelectionLength, textToReplace);

            return(true);
        }