示例#1
0
        private void SelectMatch(FindingOrder order, TextEditorBase textEditor, MatchCollection sectionMatchCollection)
        {
            switch (order)
            {
            case FindingOrder.Prev:
            {
                // Get the last match of that section, since we're going upwards
                Match lastMatch = sectionMatchCollection[sectionMatchCollection.Count - 1];

                textEditor.Select(lastMatch.Index, lastMatch.Length);                         // Select the match
                break;
            }

            case FindingOrder.Next:
            {
                // Get the first match of that section, since we're going downwards
                Match firstMatch = sectionMatchCollection[0];

                int    selectionEnd       = textEditor.SelectionStart + textEditor.SelectionLength;
                string textAfterSelection = GetTextAfterSelection(textEditor.Text, selectionEnd);
                int    cutStringLength    = textEditor.Document.TextLength - textAfterSelection.Length;

                textEditor.Select(cutStringLength + firstMatch.Index, firstMatch.Length);                         // Select the match
                break;
            }
            }

            textEditor.ScrollTo(textEditor.TextArea.Caret.Position.Line, textEditor.TextArea.Caret.Position.Column);
        }
示例#2
0
        private bool Find(FindingOrder order)
        {
            if (string.IsNullOrWhiteSpace(textBox_Find.Text))
            {
                ShowError("Invalid input.");
                return(false);
            }

            TextEditorBase currentTabTextEditor = GetTextEditorOfTab(_editorTabControl.SelectedTab);
            string         pattern = GetCurrentPattern();
            RegexOptions   options = GetCurrentRegexOptions();

            if (Regex.Matches(currentTabTextEditor.Text, pattern, options).Count == 0)             // If no matches were found in the current document
            {
                if (radioButton_Current.Checked)
                {
                    ShowError("No matches found in the current document.");                     // Search cancelled
                }
                else if (radioButton_AllTabs.Checked)
                {
                    FindMatchInAnotherTab(order, pattern, options);
                }
            }
            else             // Matches were found in the current document
            {
                return(FindMatch(order, currentTabTextEditor, pattern, options));
            }

            return(false);
        }
示例#3
0
        private bool FindMatch(FindingOrder order, TextEditorBase textEditor, string pattern, RegexOptions options)
        {
            MatchCollection sectionMatchCollection = GetMatchCollectionFromSection(order, textEditor, pattern, options);

            if (sectionMatchCollection.Count == 0)             // If no matches were found in that section of the document
            {
                if (radioButton_Current.Checked)
                {
                    EndSuccessfulSearch(order, textEditor);
                }
                else if (radioButton_AllTabs.Checked)
                {
                    FindMatchInAnotherTab(order, pattern, options);
                }
            }
            else             // Matches were found in that section of the document
            {
                SelectMatch(order, textEditor, sectionMatchCollection);

                UpdateStatusLabel(textEditor.Text, pattern, options);
                return(true);
            }

            return(false);
        }
示例#4
0
        private bool Replace(FindingOrder order)
        {
            if (!Find(order))
            {
                return(false);
            }

            ReplaceMatch();
            return(true);
        }
示例#5
0
        private void EndSuccessfulSearch(FindingOrder order, TextEditorBase textEditor)
        {
            switch (order)
            {
            case FindingOrder.Prev:
                MoveCaretToDocumentStart(textEditor);
                ShowWarning("Reached the start of the document with no more matches found.");                         // Search ends here
                break;

            case FindingOrder.Next:
                MoveCaretToDocumentEnd(textEditor);
                ShowWarning("Reached the end of the document with no more matches found.");                         // Search ends here
                break;
            }
        }
示例#6
0
        private MatchCollection GetMatchCollectionFromSection(FindingOrder order, TextEditorBase textEditor, string pattern, RegexOptions options)
        {
            switch (order)
            {
            case FindingOrder.Prev:
                string textBeforeSelection = GetTextBeforeSelection(textEditor.Text, textEditor.SelectionStart);
                return(Regex.Matches(textBeforeSelection, pattern, options));

            case FindingOrder.Next:
                int    selectionEnd       = textEditor.SelectionStart + textEditor.SelectionLength;
                string textAfterSelection = GetTextAfterSelection(textEditor.Text, selectionEnd);
                return(Regex.Matches(textAfterSelection, pattern, options));
            }

            return(null);
        }
示例#7
0
        private void FindMatchInAnotherTab(FindingOrder order, string pattern, RegexOptions options)
        {
            if (GetAllTabsMatchCount(pattern, options) == 0)    // If no matches were found in any tab
            {
                ShowError("No matches found.");                 // Search cancelled
            }
            else
            {
                switch (order)
                {
                case FindingOrder.Prev:
                    FindPrevInPrevTab();                             // Go to the previous tab to find matches there
                    break;

                case FindingOrder.Next:
                    FindNextInNextTab();                             // Go to the next tab to find matches there
                    break;
                }
            }
        }