Exemplo n.º 1
0
        private static void InsertText(IWpfTextView view, DTE2 dte, string text)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                dte.UndoContext.Open("Generate text");

                using (Microsoft.VisualStudio.Text.ITextEdit edit = view.TextBuffer.CreateEdit())
                {
                    if (!view.Selection.IsEmpty)
                    {
                        edit.Delete(view.Selection.SelectedSpans[0].Span);
                        view.Selection.Clear();
                    }

                    edit.Insert(view.Caret.Position.BufferPosition, text);
                    edit.Apply();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
            }
            finally
            {
                dte.UndoContext.Close();
            }
        }
Exemplo n.º 2
0
        private static bool RemoveTextInTextView(Microsoft.VisualStudio.Text.ITextEdit edit, string text, string pattern)
        {
            var match = Regex.Match(text, pattern);

            if (match.Success)
            {
                edit.Delete(match.Index, match.Length);
            }

            return(true);
        }