Пример #1
0
        private void ScrollToCaret(ref int valueX, ref int valueY, IntSize charSize)
        {
            if (!needScrollToCaret)
            {
                return;
            }

            needScrollToCaret = false;
            int indentX = charSize.x * scrollingIndent;
            int indentY = charSize.y * scrollingIndent;

            if (indentX > (textAreaWidth - charSize.x) / 2)
            {
                indentX = ((textAreaWidth - charSize.x) / (2 * charSize.x)) * charSize.x;
            }
            if (indentY > (textAreaHeight - charSize.y) / 2)
            {
                indentY = ((textAreaHeight - charSize.y) / (2 * charSize.y)) * charSize.y;
            }

            Pos  pos     = lines.UniversalPosOf(lines.PlaceOf(lines.LastSelection.caret));
            int  x       = pos.ix * charSize.x;
            int  y       = pos.iy * charSize.y;
            bool changed = false;

            if (valueX > x - indentX)
            {
                valueX  = x - indentX;
                changed = true;
            }
            else if (valueX < x - textAreaWidth + indentX)
            {
                valueX  = x - textAreaWidth + indentX;
                changed = true;
            }
            if (valueY > y - indentY)
            {
                valueY  = y - indentY;
                changed = true;
            }
            else if (valueY < y - textAreaHeight + indentY + charSize.y)
            {
                valueY  = y - textAreaHeight + indentY + charSize.y;
                changed = true;
            }

            if (changed)
            {
                valueX = CommonHelper.Clamp(valueX, 0, scrollX.contentSize - scrollX.areaSize);
                valueY = CommonHelper.Clamp(valueY, 0, scrollY.contentSize - scrollY.areaSize);
            }
        }
Пример #2
0
        public bool PrivateSelectAllFound(string text, bool isRegex, bool isIgnoreCase,
                                          List <SimpleRange> outRanges)
        {
            ResetOutput();

            bool   result   = true;
            string all      = controller.Lines.GetText();
            int    minIndex = 0;
            int    maxIndex = all.Length;

            Regex regex = null;

            if (isRegex)
            {
                string error;
                regex = ParseRegex(text, out error);
                if (regex == null || error != null)
                {
                    needShowError = error;
                    return(true);
                }
            }

            if (!controller.LastSelection.Empty && controller.SelectionsCount == 1)
            {
                string selectionText = all.Substring(controller.LastSelection.Left, controller.LastSelection.Count);
                bool   useArea       = false;
                if (isRegex)
                {
                    Match match = regex.Match(selectionText);
                    useArea = !match.Success || match.Length != selectionText.Length;
                }
                else
                {
                    useArea = text != selectionText;
                }
                if (useArea)
                {
                    result   = false;
                    minIndex = controller.LastSelection.Left;
                    maxIndex = controller.LastSelection.Right;
                }
            }

            LineArray        lines      = controller.Lines;
            List <Selection> selections = lines.selections;
            int  start = minIndex;
            bool found = false;
            bool first = true;

            while (true)
            {
                int index;
                int length;
                if (isRegex)
                {
                    Match match = regex.Match(all, start);
                    index  = -1;
                    length = text.Length;
                    if (match.Success)
                    {
                        index  = match.Index;
                        length = match.Length;
                    }
                }
                else
                {
                    length = text.Length;
                    CompareInfo ci = isIgnoreCase ? CultureInfo.InvariantCulture.CompareInfo : null;
                    index = ci != null?
                            ci.IndexOf(all, text, start, CompareOptions.IgnoreCase) :
                                all.IndexOf(text, start);
                }
                if (index == -1 || index + length > maxIndex)
                {
                    break;
                }
                if (outRanges == null)
                {
                    if (first)
                    {
                        first = false;
                        controller.ClearMinorSelections();
                    }
                    else
                    {
                        selections.Add(new Selection());
                    }
                    Selection selection = selections[selections.Count - 1];
                    selection.anchor = index;
                    selection.caret  = index + length;
                    lines.SetPreferredPos(selection, lines.PlaceOf(selection.caret));
                }
                else
                {
                    outRanges.Add(new SimpleRange(index, length));
                }
                start = index + length;
            }
            needMoveToCaret = found;
            return(result);
        }