public static bool FindNext()
        {
            SetSearchOptions();
            if (find == null ||
                SearchOptions.FindPattern == null ||
                SearchOptions.FindPattern.Length == 0)
            {
                return(false);
            }

            if (!find.SearchStrategy.CompilePattern())
            {
                find.Reset();
                lastResult = null;
                return(false);
            }

            TextEditorControl textArea = null;

            while (textArea == null)
            {
                var result = find.FindNext();
                if (result == null)
                {
                    find.Reset();
                    lastResult = null;
                    return(false);
                }
                else
                {
                    textArea = OpenTextArea(result.FileName);
                    if (textArea != null)
                    {
                        if (lastResult != null && lastResult.FileName == result.FileName &&
                            textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length)
                        {
                            find.Reset();
                        }
                        int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
                        int endPos   = Math.Min(textArea.Document.TextLength, startPos + result.Length);

                        SearchReplaceUtilities.SelectText(textArea, startPos, endPos);
                        lastResult = result;
                        return(true);
                    }
                }
            }
            return(false);
        }
        public static bool FindNextInSelection()
        {
            TextEditorControl textArea = null;

            while (textArea == null)
            {
                SearchResultMatch result = find.FindNext(textSelection.Offset, textSelection.Length);
                if (result == null)
                {
                    if (!_foundAtLeastOneItem)
                    {
                        ShowNotFoundMessage();
                    }
                    find.Reset();
                    lastResult           = null;
                    _foundAtLeastOneItem = false;
                    return(false);
                }
                else
                {
                    textArea = OpenTextArea(result.FileName);
                    if (textArea != null)
                    {
                        _foundAtLeastOneItem = true;
                        if (lastResult != null && lastResult.FileName == result.FileName &&
                            textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length)
                        {
                        }
                        int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
                        int endPos   = Math.Min(textArea.Document.TextLength, startPos + result.Length);
                        SearchReplaceUtilities.SelectText(textArea, startPos, endPos);
                        lastResult = result;
                    }
                }
            }
            return(true);
        }
 static void SetSearchOptions()
 {
     find.SearchStrategy   = SearchReplaceUtilities.CreateSearchStrategy(SearchOptions.SearchStrategyType);
     find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType);
 }