Пример #1
0
        public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment,
                                                                 ITextDocument document, int index, int length, int textColumnIndex)
        {
            var lineIndex      = document.GetLineFromCharIndex(textSegment.Index + index, textColumnIndex);
            var firstCharIndex = document.GetFirstCharIndexFromLine(lineIndex);
            var styleCount     = document.TextSegmentStyledManager.Get(firstCharIndex, NameKey, textColumnIndex).Count();

            if (styleCount > 0)
            {
                return(null);
            }

            var content = document.GetLineText(lineIndex, textColumnIndex);

            var isManual = _regexManual.IsMatch(content); // Regex.IsMatch(content, "^\\d:");
            var isSwitch = _regexSwitch.IsMatch(content); // Regex.IsMatch(content, "^-[^\\-]");

            if (isManual || isSwitch)
            {
                var segment = document.CreateStyledTextSegment(this);
                segment.Index = 0;
                segment.SetLength(textColumnIndex, 1);
                segment.Object =
                    isManual ? int.Parse("" + document.GetCharFromIndex(firstCharIndex, textColumnIndex)) : -1;

                return(segment);
            }

            if (content.StartsWith("["))
            {
                var match = _regexTimestamp.Match(content);
                if (match.Success)
                {
                    if (string.IsNullOrEmpty(match.Groups[3].Value) == false)
                    {
                        var segment = document.CreateStyledTextSegment(this);
                        segment.Index = 0;
                        segment.SetLength(textColumnIndex, content.Length);
                        segment.Object = -2;

                        return(segment);
                    }
                }
            }

            return(null);
        }