Exemplo n.º 1
0
        void UpdateLinksOnTextReplace(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e)
        {
            wasReplaced = true;

            if (e.EditTag != _linkEditTag)
            {
                foreach (var change in e.Changes)
                {
                    int offset = change.OldPosition - baseOffset;
                    if (!links.Any(link => link.Links.Any(segment => segment.Contains(offset) ||
                                                          segment.EndOffset == offset)))
                    {
                        SetCaretPosition = false;
                        ExitTextLinkMode();
                        return;
                    }
                }
            }

            foreach (TextLink link in links)
            {
                var newLinks = new List <ISegment>();
                foreach (var s in link.Links)
                {
                    var newStart = Microsoft.VisualStudio.Text.Tracking.TrackPositionForwardInTime(Microsoft.VisualStudio.Text.PointTrackingMode.Negative,
                                                                                                   s.Offset + baseOffset,
                                                                                                   e.BeforeVersion, e.AfterVersion) - baseOffset;
                    var newEnd = Microsoft.VisualStudio.Text.Tracking.TrackPositionForwardInTime(Microsoft.VisualStudio.Text.PointTrackingMode.Positive,
                                                                                                 s.Offset + s.Length + baseOffset,
                                                                                                 e.BeforeVersion, e.AfterVersion) - baseOffset;

                    newLinks.Add(new TextSegment(newStart, newEnd - newStart));
                }

                link.Links = newLinks;
            }

            // If this is the final edit of a compund edit (e.g. no one has modified the buffer in an event handler before this one).
            if (Editor.Document.TextBuffer.CurrentSnapshot == e.After)
            {
                // Edits due to replacing link text trigger a commit. Otherwise, update the link text
                if (e.EditTag == _linkEditTag)
                {
                    // TODO this really should be triggered on the post change if there were any link-inspired updates.
                    foreach (TextLink link in links)
                    {
                        for (int i = 0; (i < link.Links.Count); ++i)
                        {
                            var s      = link.Links[i];
                            int offset = s.Offset + baseOffset;
                            Editor.Document.CommitLineUpdate(Editor.Document.OffsetToLineNumber(offset));
                        }
                    }
                }
                else
                {
                    UpdateTextLinks();
                }
            }
        }
Exemplo n.º 2
0
        #pragma warning restore VSTHRD100

        private void TextBuffer_ChangedLowPriority(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e)
        {
            var changedSpans = e.Changes.Select(c => c.OldSpan);

            foreach (var span in changedSpans)
            {
                HistoryHelper.AddItemToHistory(_control.CodeDocumentViewModel, span);
            }
        }
Exemplo n.º 3
0
 void TextBuffer_Changed(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e)
 {
     foreach (var change in e.Changes)
     {
         string text = change.NewText.ToString();
         while (text.Length > 4090)
         {
             Trace.Write("Following lines exceeded 4090 chars!\n");
             var part    = text.Substring(0, 4090);
             int nlIndex = part.LastIndexOf("\n", 0);
             if (nlIndex == -1)
             {
                 Trace.Write(part);
                 text = text.Substring(4091);
             }
             else
             {
                 Trace.Write(part.Substring(0, nlIndex + 1));
                 text = text.Substring(nlIndex + 1);
             }
         }
         Trace.Write(text);
     }
 }
Exemplo n.º 4
0
 void UpdateAnalysisDocument(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e)
 {
     providedAnalysisDocument = textView.TextSnapshot.GetOpenDocumentInCurrentContextWithChanges();
     outlineReady             = true; // we need this to compensate for the old behaviour
     UpdateDocumentOutline(this, e);
 }
 private void BufferTextChanged(object sender, Microsoft.VisualStudio.Text.TextContentChangedEventArgs e)
 {
     LogActiveDocument();
 }