Ejemplo n.º 1
0
        // Find next result
        public bool FindNext(FindReplaceOptions options)
        {
            byte[]           data = editor.GetText();
            string           text = Encoding.GetEncoding(config.CodePage).GetString(data);
            StringComparison mode = options.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
            int  startpos         = Math.Max(editor.SelectionStart, editor.SelectionEnd);
            bool wrapped          = false;

            while (true)
            {
                int result = text.IndexOf(options.FindText, startpos, mode);
                if (result > -1)
                {
                    // Check to see if it is the whole word
                    if (options.WholeWord)
                    {
                        // Veryfy that we have found a whole word
                        string foundword = editor.GetWordAt(result + 1);
                        if (foundword.Length != options.FindText.Length)
                        {
                            startpos = result + 1;
                            result   = -1;
                        }
                    }

                    // Still ok?
                    if (result > -1)
                    {
                        // Select the result
                        editor.SelectionStart = result;
                        editor.SelectionEnd   = result + options.FindText.Length;
                        editor.EnsureLineVisible(editor.LineFromPosition(editor.SelectionEnd));
                        return(true);
                    }
                }
                else
                {
                    // If we haven't tried from the start, try from the start now
                    if ((startpos > 0) && !wrapped)
                    {
                        startpos = 0;
                        wrapped  = true;
                    }
                    else
                    {
                        // Can't find it
                        return(false);
                    }
                }
            }
        }