void UpdateLinkText(TextLink link, Microsoft.VisualStudio.Text.ITextEdit edit)
        {
            for (int i = 0; (i < link.Links.Count); ++i)
            {
                var s      = link.Links[i];
                int offset = s.Offset + baseOffset;
                if (offset < 0 || s.Length < 0 || offset + s.Length > Editor.Document.Length)
                {
                    // This should never happen since it implies a corrupted link/bad update following a text change.
                    continue;
                }

                var span = new Microsoft.VisualStudio.Text.Span(offset, s.Length);
                if (edit.Snapshot.GetText(span) != link.CurrentText)
                {
                    edit.Replace(span, link.CurrentText);
                }
            }
        }
 void UpdateTextLink(TextLink link, Microsoft.VisualStudio.Text.ITextEdit edit)
 {
     if (link.GetStringFunc != null)
     {
         link.Values = link.GetStringFunc(GetStringCallback);
     }
     if (!link.IsEditable && link.Values != null && link.Values.Count > 0)
     {
         link.CurrentText = (string)link.Values [link.Values.Count - 1];
     }
     else
     {
         if (!link.PrimaryLink.IsInvalid())
         {
             int offset = link.PrimaryLink.Offset + baseOffset;
             if (offset >= 0 && link.PrimaryLink.Length >= 0)
             {
                 link.CurrentText = Editor.Document.GetTextAt(offset, link.PrimaryLink.Length);
             }
         }
     }
     UpdateLinkText(link, edit);
 }
Beispiel #3
0
 public void WriteToTextViewer(string codeToWrite, IWpfTextView viewer, int offset)
 {
     Microsoft.VisualStudio.Text.ITextEdit ie = viewer.Selection.TextView.TextBuffer.CreateEdit();
     ie.Insert(offset, codeToWrite);
     ie.Apply();
 }