Ejemplo n.º 1
0
        int FindWordStart(Document.Document document, int offset)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);

            if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && Char.IsWhiteSpace(document.GetCharAt(offset)))
            {
                while (offset > line.Offset && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
                {
                    --offset;
                }
            }
            else if (IsSelectableChar(document.GetCharAt(offset)) || (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset)) && IsSelectableChar(document.GetCharAt(offset - 1))))
            {
                while (offset > line.Offset && IsSelectableChar(document.GetCharAt(offset - 1)))
                {
                    --offset;
                }
            }
            else
            {
                if (offset > 0 && !Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && !IsSelectableChar(document.GetCharAt(offset - 1)))
                {
                    return(Math.Max(0, offset - 1));
                }
            }
            return(offset);
        }
        public TextEditorControl()
        {
            SetStyle(ControlStyles.ContainerControl, true);

            _textAreaPanel.Dock = DockStyle.Fill;

            //Document = (new DocumentFactory()).CreateDocument();
            //Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy();
            Document = new Document.Document();

            _primaryTextAreaControl = new TextAreaControl(this);
            ActiveTextAreaControl   = _primaryTextAreaControl;

            _primaryTextAreaControl.TextArea.GotFocus += delegate
            {
                SetActiveTextAreaControl(_primaryTextAreaControl);
            };

            _primaryTextAreaControl.Dock = DockStyle.Fill;
            _textAreaPanel.Controls.Add(_primaryTextAreaControl);
            InitializeTextAreaControl(_primaryTextAreaControl);
            Controls.Add(_textAreaPanel);
            ResizeRedraw             = true;
            Document.UpdateCommited += CommitUpdateRequested;
            OptionsChanged();
        }
Ejemplo n.º 3
0
        int FindNext(Document.Document document, int offset, char ch)
        {
            LineSegment line   = document.GetLineSegmentForOffset(offset);
            int         endPos = line.Offset + line.Length;

            while (offset < endPos && document.GetCharAt(offset) != ch)
            {
                ++offset;
            }
            return(offset);
        }
Ejemplo n.º 4
0
        public Highlight GetHighlight(Document.Document document, int offset)
        {
            int searchOffset;

            if (Shared.TEP.BracketMatchingStyle == BracketMatchingStyle.After)
            {
                searchOffset = offset;
            }
            else
            {
                searchOffset = offset + 1;
            }
            char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, searchOffset)));

            TextLocation endP = document.OffsetToPosition(searchOffset);

            if (word == OpenTag)
            {
                if (searchOffset < document.TextLength)
                {
                    int bracketOffset = TextUtilities.SearchBracketForward(document, searchOffset + 1, OpenTag, ClosingTag);
                    if (bracketOffset >= 0)
                    {
                        TextLocation p = document.OffsetToPosition(bracketOffset);
                        return(new Highlight(p, endP));
                    }
                }
            }
            else if (word == ClosingTag)
            {
                if (searchOffset > 0)
                {
                    int bracketOffset = TextUtilities.SearchBracketBackward(document, searchOffset - 1, OpenTag, ClosingTag);
                    if (bracketOffset >= 0)
                    {
                        TextLocation p = document.OffsetToPosition(bracketOffset);
                        return(new Highlight(p, endP));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        int FindWordEnd(Document.Document document, int offset)
        {
            LineSegment line = document.GetLineSegmentForOffset(offset);

            if (line.Length == 0)
            {
                return(offset);
            }
            int endPos = line.Offset + line.Length;

            offset = Math.Min(offset, endPos - 1);

            if (IsSelectableChar(document.GetCharAt(offset)))
            {
                while (offset < endPos && IsSelectableChar(document.GetCharAt(offset)))
                {
                    ++offset;
                }
            }
            else if (Char.IsWhiteSpace(document.GetCharAt(offset)))
            {
                if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
                {
                    while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset)))
                    {
                        ++offset;
                    }
                }
            }
            else
            {
                return(Math.Max(0, offset + 1));
            }

            return(offset);
        }