Exemplo n.º 1
0
        /// <summary>
        /// 搜索多个目标
        /// </summary>
        /// <param name="strSearch">需要搜索的字符串</param>
        /// <returns>搜索到的目标字符串的位置</returns>
        public int[] SearchMulti(string strSearch)
        {
            _editor.MultipleSelection = true;
            var poses = System.Text.RegularExpressions.Regex.Matches(_editor.Text, strSearch).Cast <System.Text.RegularExpressions.Match>().Select(x => x.Index).ToArray();

            _editor.ClearSelections();
            foreach (var item in poses)
            {
                _editor.AddSelection(item, item + strSearch.Length);
            }

            return(poses);
        }
Exemplo n.º 2
0
 private void ReplaceText(IWin32Window window, string searchText, string replacementText, ReplaceMode mode, bool matchCase, bool wholeWord, bool isRegex, bool wrap)
 {
     if (searchText != null && replacementText != null)
     {
         int replacementLength = replacementText.Length;
         if (mode == ReplaceMode.Next)
         {
             if (_editor.SelectionStart == _editor.SelectionEnd)
             {
                 SearchText(window, searchText, SearchDirection.Next, matchCase, wholeWord, isRegex, wrap);
             }
             if (_editor.SelectionStart < _editor.SelectionEnd)
             {
                 int selStart = _editor.SelectionStart;
                 _editor.ReplaceSelection(replacementText);
                 _editor.ClearSelections();
                 _editor.GotoPosition(selStart + replacementLength);
                 _editor.Focus();
             }
         }
         else
         {
             Match  match;
             int    searchStart = 0;
             string text        = _editor.Text;
             while ((match = GetSearchMatch(text, searchText, searchStart, SearchDirection.Next, matchCase, wholeWord, isRegex, false)) != null)
             {
                 if (!match.Success)
                 {
                     break;
                 }
                 text        = text.Insert(match.Index + match.Length, replacementText);
                 text        = text.Remove(match.Index, match.Length);
                 searchStart = match.Index + replacementLength;
             }
             _editor.Text = text;
         }
     }
 }
Exemplo n.º 3
0
 public void ClearSelection()
 {
     textArea.ClearSelections();
 }
Exemplo n.º 4
0
        public void Find(bool next, string search)
        {
            if (search.Length > 0)
            {
                if (next)
                {
                    // SEARCH FOR THE NEXT OCCURANCE

                    // Search the document from the caret onwards
                    TextArea.TargetStart = TextArea.CurrentPosition;
                    TextArea.TargetEnd   = TextArea.TextLength;
                    TextArea.SearchFlags = MainWindowVM.searchFlags;

                    // Search, and if not found..
                    if (TextArea.SearchInTarget(search) == -1)
                    {
                        // Search again from top
                        TextArea.TargetStart = 0;
                        TextArea.TargetEnd   = TextArea.TextLength;

                        // Search, and if not found..
                        if (TextArea.SearchInTarget(search) == -1)
                        {
                            // clear selection and exit
                            TextArea.ClearSelections();
                            return;
                        }
                    }
                }
                else
                {
                    // SEARCH FOR THE PREVIOUS OCCURANCE

                    // Search the document from the caret backwards
                    TextArea.TargetStart = TextArea.CurrentPosition - 1;
                    TextArea.TargetEnd   = 0;
                    TextArea.SearchFlags = MainWindowVM.searchFlags;

                    // Search, and if not found..
                    if (TextArea.SearchInTarget(search) == -1)
                    {
                        // Search again from top
                        TextArea.TargetStart = TextArea.TextLength;
                        TextArea.TargetEnd   = 0;

                        // Search, and if not found..
                        if (TextArea.SearchInTarget(search) == -1)
                        {
                            // clear selection and exit
                            TextArea.ClearSelections();
                            return;
                        }
                    }
                }

                // Select the occurance
                TextArea.SetSelection(TextArea.TargetEnd, TextArea.TargetStart);
                TextArea.ScrollCaret();
                HighLight(MainWindowVM.highlightAll ? search : "");
            }
        }
        public static void Find(bool next, bool incremental)
        {
            bool first = LastSearch != SearchBox.Text;

            LastSearch = SearchBox.Text;
            if (LastSearch.Length > 0)
            {
                if (next)
                {
                    // SEARCH FOR THE NEXT OCCURANCE

                    // Search the document at the last search index
                    TextArea.TargetStart = LastSearchIndex - 1;
                    TextArea.TargetEnd   = LastSearchIndex + (LastSearch.Length + 1);
                    TextArea.SearchFlags = SearchFlags.None;

                    // Search, and if not found..
                    if (!incremental || TextArea.SearchInTarget(LastSearch) == -1)
                    {
                        // Search the document from the caret onwards
                        TextArea.TargetStart = TextArea.CurrentPosition;
                        TextArea.TargetEnd   = TextArea.TextLength;
                        TextArea.SearchFlags = SearchFlags.None;

                        // Search, and if not found..
                        if (TextArea.SearchInTarget(LastSearch) == -1)
                        {
                            // Search again from top
                            TextArea.TargetStart = 0;
                            TextArea.TargetEnd   = TextArea.TextLength;

                            // Search, and if not found..
                            if (TextArea.SearchInTarget(LastSearch) == -1)
                            {
                                // clear selection and exit
                                TextArea.ClearSelections();
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // SEARCH FOR THE PREVIOUS OCCURANCE

                    // Search the document from the beginning to the caret
                    TextArea.TargetStart = 0;
                    TextArea.TargetEnd   = TextArea.CurrentPosition;
                    TextArea.SearchFlags = SearchFlags.None;

                    // Search, and if not found..
                    if (TextArea.SearchInTarget(LastSearch) == -1)
                    {
                        // Search again from the caret onwards
                        TextArea.TargetStart = TextArea.CurrentPosition;
                        TextArea.TargetEnd   = TextArea.TextLength;

                        // Search, and if not found..
                        if (TextArea.SearchInTarget(LastSearch) == -1)
                        {
                            // clear selection and exit
                            TextArea.ClearSelections();
                            return;
                        }
                    }
                }

                // Select the occurance
                LastSearchIndex = TextArea.TargetStart;
                TextArea.SetSelection(TextArea.TargetEnd, TextArea.TargetStart);
                TextArea.ScrollCaret();
            }

            SearchBox.Focus();
        }