Esempio n. 1
0
        void ReparseFile(object sender, EventArgs args)
        {
            ITextSnapshot snapshot = _buffer.CurrentSnapshot;

            List <MarkdownSection> newSections = new List <MarkdownSection>(
                MarkdownParser.ParseMarkdownSections(snapshot)
                .Select(t => new MarkdownSection()
            {
                TokenType = t.TokenType,
                Span      = snapshot.CreateTrackingSpan(t.Span, SpanTrackingMode.EdgeExclusive)
            }));

            NormalizedSnapshotSpanCollection oldSectionSpans = new NormalizedSnapshotSpanCollection(
                _sections.Select(s => s.Span.GetSpan(snapshot)));
            NormalizedSnapshotSpanCollection newSectionSpans = new NormalizedSnapshotSpanCollection(
                newSections.Select(s => s.Span.GetSpan(snapshot)));

            NormalizedSnapshotSpanCollection difference = SymmetricDifference(oldSectionSpans, newSectionSpans);

            _sections = newSections;

            foreach (var span in difference)
            {
                var temp = TagsChanged;
                if (temp != null)
                {
                    temp(this, new SnapshotSpanEventArgs(span));
                }
            }
        }
        protected override void ReParseImpl()
        {
            ITextSnapshot snapshot  = TextBuffer.CurrentSnapshot;
            Stopwatch     stopwatch = Stopwatch.StartNew();

            List <MarkdownSection> sections = new List <MarkdownSection>(
                MarkdownParser.ParseMarkdownSections(snapshot)
                .Select(t => new MarkdownSection()
            {
                TokenType = t.TokenType,
                Span      = snapshot.CreateTrackingSpan(t.Span, SpanTrackingMode.EdgeExclusive)
            }));

            OnParseComplete(new MarkdownParseResultEventArgs(sections, snapshot, stopwatch.Elapsed));
        }
Esempio n. 3
0
        void RefreshComboItems(object sender, EventArgs args)
        {
            try
            {
                ignoreComboChange = true;

                ITextSnapshot snapshot = textView.TextBuffer.CurrentSnapshot;

                sections = new List <MarkdownSection>(
                    MarkdownParser.ParseMarkdownSections(snapshot)
                    .Select(t => new MarkdownSection()
                {
                    TokenType = t.TokenType,
                    Span      = snapshot.CreateTrackingSpan(t.Span, SpanTrackingMode.EdgeExclusive)
                }));

                sectionCombo.Items.Clear();

                // First, add an item for "Top of the file"
                sectionCombo.Items.Add(" (Top of file)");

                foreach (var section in sections)
                {
                    var    lineText  = section.Span.GetStartPoint(snapshot).GetContainingLine().GetText().TrimStart(' ', '\t', '#');
                    string spaces    = new string('-', section.TokenType - MarkdownParser.TokenType.H1);
                    string comboText = string.Format("{0}{1}", spaces, lineText);

                    sectionCombo.Items.Add(comboText);
                }

                SetSectionComboToCaretPosition();
            }
            finally
            {
                ignoreComboChange = false;
            }
        }