public FindResult FindNext()

in src/XmlNotepad/XmlTreeViewFindTarget.cs [202:300]


        public FindResult FindNext(string expression, FindFlags flags, SearchFilter filter)
        {

            CheckCurrentState(expression, flags, filter);

            this._match = null;

            if (string.IsNullOrEmpty(expression))
                return FindResult.None;

            if (this._list == null)
            {
                FindNodes();
                this._position = -1;
                this._start = -1; // we have not yet moved to one of the found nodes.
            }
            else if (this._resetPosition)
            {
                this._resetPosition = false;
                FindNodes();
                if (this._start >= _list.Count)
                {
                    this._start = _list.Count - 1;
                }
                if (this._position >= _list.Count)
                {
                    this._position = _list.Count - 1;
                }
            }

            int s = this._start;
            bool first = (this._start == -1);

            var rc = FindSelectedNode();
            int pos = rc.Item1;
            bool exact = rc.Item2;

            if (pos != this._position)
            {
                // user has moved the selection somewhere else, so start the find ring over again.
                first = true;
            }

            bool hasSomething = this._list != null && this._list.Count > 0;
            while (hasSomething)
            {
                if (this.Backwards)
                {
                    pos--;
                    if (pos < 0) pos = _list.Count - 1;
                }
                else
                {
                    pos++;
                    if (pos >= _list.Count) pos = 0;
                }

                if (first)
                {
                    this._start = s = pos;
                }
                else if (pos == this._start)
                {
                    // we have wrapped around!
                    break;
                }

                this._position = pos;

                XmlNodeMatch m = _list[pos] as XmlNodeMatch;
                XmlNode node = m.Node;
                this._match = m;

                if (node != null)
                {
                    this._current = this._view.FindNode(node);
                    if (this._current != null)
                    {
                        this._view.SelectedNode = this._current;
                        if (m.IsName)
                        {
                            _ev = this._view.TreeView;
                        }
                        else
                        {
                            _ev = this._view.NodeTextView;
                        }
                        if (_ev.BeginEdit(null))
                        {
                            _ev.SelectText(m.Index, m.Length);
                        }
                    }
                }
                return FindResult.Found;
            }

            this._start = -1; // get ready for another cycle around.
            return hasSomething ? FindResult.NoMore : FindResult.None;
        }