예제 #1
0
        private void txtFind_TextChanged(object sender, EventArgs e)
        {
            this.txtFind.BackColor = SystemColors.Window;
            if (this.txtFind.Text == string.Empty)
            {
                return;
            }
            if (this._scintilla == null)
            {
                return;
            }

            int            pos = Math.Min(this._scintilla.CurrentPosition, this._scintilla.AnchorPosition);
            CharacterRange r   = this._findReplace.FindReplace.Find(pos, this._scintilla.TextLength, this.txtFind.Text, this._findReplace.GetSearchFlags());

            if (r.cpMin == r.cpMax)
            {
                r = this._findReplace.FindReplace.Find(0, pos, this.txtFind.Text, this._findReplace.GetSearchFlags());
            }

            if (r.cpMin != r.cpMax)
            {
                this._scintilla.SetSel(r.cpMin, r.cpMax);
            }
            else
            {
                this.txtFind.BackColor = Color.Tomato;
            }

            this.MoveFormAwayFromSelection();
        }
        public CharacterRange FindPrevious(Regex findExpression, bool wrap, CharacterRange searchRange)
        {
            var caret = this.Scintilla.CurrentPosition;

            if (!(caret >= searchRange.cpMin && caret <= searchRange.cpMax))
            {
                return(this.Find(searchRange.cpMin, searchRange.cpMax, findExpression, true));
            }

            var anchor = this.Scintilla.AnchorPosition;

            if (!(anchor >= searchRange.cpMin && anchor <= searchRange.cpMax))
            {
                anchor = caret;
            }

            var r = this.Find(searchRange.cpMin, anchor, findExpression, true);

            if (r.cpMin != r.cpMax)
            {
                return(r);
            }
            else if (wrap)
            {
                return(this.Find(anchor, searchRange.cpMax, findExpression, true));
            }
            else
            {
                return(new CharacterRange());
            }
        }
 public CharacterRange Find(CharacterRange rangeToSearch, string searchString, SearchFlags searchflags, bool searchUp)
 {
     if (searchUp)
     {
         return(this.Find(rangeToSearch.cpMax, rangeToSearch.cpMin, searchString, searchflags));
     }
     else
     {
         return(this.Find(rangeToSearch.cpMin, rangeToSearch.cpMax, searchString, searchflags));
     }
 }
        public CharacterRange Find(CharacterRange r, Regex findExpression, bool searchUp)
        {
            // Single line and Multi Line in RegExp doesn't really effect
            // whether or not a match will include newline characters. This
            // means we can't do a line by line search. We have to search
            // the entire range because it could potentially match the
            // entire range.

            var text = this.Scintilla.GetTextRange(r.cpMin, r.cpMax - r.cpMin + 1);

            var m = findExpression.Match(text);

            if (!m.Success)
            {
                return(new CharacterRange());
            }

            if (searchUp)
            {
                // Since we can't search backwards with RegExp we
                // have to search the entire string and return the
                // last match. Not the most efficient way of doing
                // things but it works.
                var range = new CharacterRange();
                while (m.Success)
                {
                    //TODO - check that removing the byte count does not upset anything
                    //int start = r.cpMin + _scintilla.Encoding.GetByteCount(text.Substring(0, m.Index));
                    //int end = _scintilla.Encoding.GetByteCount(text.Substring(m.Index, m.Length));
                    var start = r.cpMin + text.Substring(0, m.Index).Length;
                    var end   = text.Substring(m.Index, m.Length).Length;

                    range = new CharacterRange(start, start + end);
                    m     = m.NextMatch();
                }

                return(range);
            }
            else
            {
                //TODO - check that removing the byte count does not upset anything
                //int start = r.cpMin + _scintilla.Encoding.GetByteCount(text.Substring(0, m.Index));
                //int end = _scintilla.Encoding.GetByteCount(text.Substring(m.Index, m.Length));
                var start = r.cpMin + text.Substring(0, m.Index).Length;
                var end   = text.Substring(m.Index, m.Length).Length;

                return(new CharacterRange(start, start + end));
            }
        }
예제 #5
0
        private void findPrevious()
        {
            if (this.txtFind.Text == string.Empty)
            {
                return;
            }
            if (this._scintilla == null)
            {
                return;
            }

            CharacterRange r = this._findReplace.FindReplace.FindPrevious(this.txtFind.Text, true, this._findReplace.GetSearchFlags());

            if (r.cpMin != r.cpMax)
            {
                this._scintilla.SetSel(r.cpMin, r.cpMax);
            }

            this.MoveFormAwayFromSelection();
        }
        public List <CharacterRange> FindAll(CharacterRange rangeToSearch, Regex findExpression, bool mark, bool highlight)
        {
            var results = new List <CharacterRange>();

            this.Scintilla.IndicatorCurrent = this.Indicator.Index;

            var findCount = 0;
            var lastLine  = -1;

            while (true)
            {
                var r = this.Find(rangeToSearch, findExpression);
                if (r.cpMin == r.cpMax)
                {
                    break;
                }

                results.Add(r);
                findCount++;
                if (mark)
                {
                    //	We can of course have multiple instances of a find on a single
                    //	line. We don't want to mark this line more than once.
                    var line = new Line(this.Scintilla, this.Scintilla.LineFromPosition(r.cpMin));
                    if (line.Position > lastLine)
                    {
                        line.MarkerAdd(this.Marker.Index);
                    }
                    lastLine = line.Position;
                }
                if (highlight)
                {
                    this.Scintilla.IndicatorFillRange(r.cpMin, r.cpMax - r.cpMin);
                }
                rangeToSearch = new CharacterRange(r.cpMax, rangeToSearch.cpMax);
            }

            this.FindAllResults?.Invoke(this, new FindResultsEventArgs(this, results));

            return(results);
        }
        public CharacterRange FindNext(Regex findExpression, bool wrap, CharacterRange searchRange)
        {
            var caret = this.Scintilla.CurrentPosition;

            if (!(caret >= searchRange.cpMin && caret <= searchRange.cpMax))
            {
                return(this.Find(searchRange.cpMin, searchRange.cpMax, findExpression, false));
            }

            var r = this.Find(caret, searchRange.cpMax, findExpression);

            if (r.cpMin != r.cpMax)
            {
                return(r);
            }
            else if (wrap)
            {
                return(this.Find(searchRange.cpMin, caret, findExpression));
            }
            else
            {
                return(new CharacterRange());
            }
        }
 public CharacterRange Find(CharacterRange r, Regex findExpression)
 {
     return(this.Find(r, findExpression, false));
 }
 public List <CharacterRange> FindAll(CharacterRange rangeToSearch, string searchString, SearchFlags flags, bool mark, bool highlight)
 {
     return(this.FindAll(rangeToSearch.cpMin, rangeToSearch.cpMax, searchString, Flags, mark, highlight));
 }
예제 #10
0
        public CharacterRange FindPrevious(string searchString, bool wrap, SearchFlags flags, CharacterRange searchRange)
        {
            var caret = this.Scintilla.CurrentPosition;

            if (!(caret >= searchRange.cpMin && caret <= searchRange.cpMax))
            {
                return(this.Find(searchRange.cpMax, searchRange.cpMin, searchString, flags));
            }

            var anchor = this.Scintilla.AnchorPosition;

            if (!(anchor >= searchRange.cpMin && anchor <= searchRange.cpMax))
            {
                anchor = caret;
            }

            var r = this.Find(anchor, searchRange.cpMin, searchString, flags);

            if (r.cpMin != r.cpMax)
            {
                return(r);
            }
            else if (wrap)
            {
                return(this.Find(searchRange.cpMax, anchor, searchString, flags));
            }
            else
            {
                return(new CharacterRange());
            }
        }
예제 #11
0
        public CharacterRange FindNext(string searchString, bool wrap, SearchFlags flags, CharacterRange searchRange)
        {
            var caret = this.Scintilla.CurrentPosition;

            if (!(caret >= searchRange.cpMin && caret <= searchRange.cpMax))
            {
                return(this.Find(searchRange.cpMin, searchRange.cpMax, searchString, flags));
            }

            var r = this.Find(caret, searchRange.cpMax, searchString, flags);

            if (r.cpMin != r.cpMax)
            {
                return(r);
            }
            else if (wrap)
            {
                return(this.Find(searchRange.cpMin, caret, searchString, flags));
            }
            else
            {
                return(new CharacterRange());
            }
        }
예제 #12
0
 public CharacterRange Find(CharacterRange rangeToSearch, string searchString, SearchFlags searchflags)
 {
     return(this.Find(rangeToSearch.cpMin, rangeToSearch.cpMax, searchString, searchflags));
 }