Ejemplo n.º 1
0
        public void SearchFindPrevious(string sTextPtn, bool searchUseRegex)
        {
            //AzukiのAnnの検索処理を利用

            Sgry.Azuki.Document azdoc = azukiControl.Document;
            int         startIndex;
            TextSegment result;
            Regex       regex;

            int s, e;

            azdoc.GetSelection(out s, out e);
            searchAnchorIndex = s - 1;

            // determine where to start text search
            if (0 <= searchAnchorIndex)
            {
                startIndex = searchAnchorIndex;
            }
            else
            {
                startIndex = Math.Min(azdoc.CaretIndex, azdoc.AnchorIndex);
            }

            // find
            if (searchUseRegex)
            {
                // Regular expression search.
                // get regex object from context
                regex = searchRegex;
                if (regex == null)
                {
                    // current text pattern was invalid as a regular expression.
                    return;
                }

                // ensure that "RightToLeft" option of the regex object is set
                RegexOptions opt = searchRegex.Options;
                if ((opt & RegexOptions.RightToLeft) == 0)
                {
                    opt        |= RegexOptions.RightToLeft;
                    searchRegex = new Regex(searchRegex.ToString(), opt);
                }
                result = azdoc.FindPrev(searchRegex, 0, startIndex);
            }
            else
            {
                // normal text pattern matching.
                result = azdoc.FindPrev(sTextPtn, 0, startIndex, searchMatchCase);
            }

            // select the result
            if (result != null)
            {
                azukiControl.Document.SetSelection(result.End, result.Begin);
                azukiControl.View.SetDesiredColumn();
                azukiControl.ScrollToCaret();
            }
            else
            {
                MessageBox.Show("見つかりません");
            }
        }
Ejemplo n.º 2
0
        public bool SearchFindPrevious(string sTextPtn, bool searchUseRegex)
        {
            //AzukiのAnnの検索処理を利用

            Sgry.Azuki.Document azdoc = ac.Document;
            int         startIndex;
            TextSegment result;
            Regex       regex;

            if (searchAnchorIndex == -1)
            {
                searchAnchorIndex = select.Begin;
            }
            else
            {
                ac.GetSelection(out int st, out int ed);
                searchAnchorIndex = st - 1;
            }

            // determine where to start text search
            if (0 <= searchAnchorIndex)
            {
                startIndex = searchAnchorIndex;
            }
            else
            {
                startIndex = Math.Min(azdoc.CaretIndex, azdoc.AnchorIndex);
            }

            // find
            if (searchUseRegex)
            {
                // Regular expression search.
                // get regex object from context
                regex = searchRegex;
                if (regex == null)
                {
                    return(false);
                }

                // ensure that "RightToLeft" option of the regex object is set
                RegexOptions opt = searchRegex.Options;
                if ((opt & RegexOptions.RightToLeft) == 0)
                {
                    opt        |= RegexOptions.RightToLeft;
                    searchRegex = new Regex(searchRegex.ToString(), opt);
                }
                result = azdoc.FindPrev(searchRegex, 0, startIndex);
            }
            else
            {
                // normal text pattern matching.
                result = azdoc.FindPrev(sTextPtn, 0, startIndex, searchMatchCase);
            }

            // select the result
            if (result == null)
            {
                return(false);
            }
            if (select.Begin != select.End && result.End <= select.Begin)
            {
                return(false);
            }

            ac.Document.SetSelection(result.Begin, result.End);
            ac.View.SetDesiredColumn();
            ac.ScrollToCaret();
            searchAnchorIndex = result.Begin;

            return(true);
        }