public override void IndentLine(TextDocument document, DocumentLine line)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }
            DocumentLine previousLine = line.PreviousLine;

            if (previousLine != null)
            {
                DocumentLine PrevPrevLine = previousLine.PreviousLine;
                ISegment     indentationSegmentPrevPrevLine = null;

                if (PrevPrevLine != null)
                {
                    indentationSegmentPrevPrevLine = TextUtilities.GetWhitespaceAfter(document, PrevPrevLine.Offset);
                }

                ISegment indentationSegmentPrevLine = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);

                string   indentation = document.GetText(indentationSegmentPrevLine);
                ISegment indentationSegmentCurLine = TextUtilities.GetWhitespaceAfter(document, line.Offset);


                IToken elem      = lexter.GetTreeElementByOffset(line);
                IToken prev_elem = (PrevPrevLine != null) ? lexter.GetTreeElementByOffset(PrevPrevLine) : null;

                if ((elem != null))
                {
                    //нашли нужный токен, ищем отступ, который необходимо сделать
                    string indent = document.GetText(TextUtilities.GetWhitespaceBefore(document, elem.StartIndex));
                    if (prev_elem != null)
                    {
                        if ((prev_elem.StartIndex >= elem.StartIndex) && (prev_elem.StopIndex <= elem.StopIndex))
                        {
                            document.Replace(indentationSegmentCurLine, indent);
                        }
                    }
                    document.Replace(indentationSegmentCurLine, indent);
                }
            }
        }
示例#2
0
        public override void SetStartupWord()
        {
            int    cursor_offset = TextArea.Caret.Offset;
            IToken token         = lexter.GetTreeElementByOffset(cursor_offset);

            if ((token != null) && ((token.StartIndex - 1) <= cursor_offset) && ((token.StopIndex + 1) >= cursor_offset))
            {
                string text = token.Text.Trim();
                if ((text.Length != 0) || (text.Length >= cursor_offset - token.StartIndex))
                {
                    completionWindow.CompletionList.SelectItem(text.Substring(0, cursor_offset - token.StartIndex));
                }
                completionWindow.StartOffset = token.StartIndex;
                completionWindow.EndOffset   = token.StartIndex + text.Length;
            }
        }