示例#1
0
        private ITextView TestAutoFormat(int position, string initialContent = "")
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(initialContent, position, out ast);

            textView.TextBuffer.Changed += (object sender, TextContentChangedEventArgs e) => {
                ast.ReflectTextChanges(e.ConvertToRelative());

                if (e.Changes[0].NewText.Length == 1)
                {
                    char ch = e.Changes[0].NewText[0];
                    if (AutoFormat.IsPreProcessAutoformatTriggerCharacter(ch))
                    {
                        position = e.Changes[0].OldPosition + 1;
                        FormatOperations.FormatCurrentLine(textView, textView.TextBuffer, _exportProvider.GetExportedValue <IEditorShell>());
                        textView.Caret.MoveTo(new SnapshotPoint(e.After, position));
                    }
                }
                else
                {
                    ITextSnapshotLine line = e.After.GetLineFromPosition(position);
                    textView.Caret.MoveTo(new SnapshotPoint(e.After, Math.Min(e.After.Length, line.Length + 1)));
                }
            };

            Typing.Type(textView.TextBuffer, position, "\n");

            return(textView);
        }
示例#2
0
 public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
 {
     if (group == VSConstants.VSStd2K)
     {
         char typedChar = GetTypedChar(group, id, inputArg);
         if (AutoFormat.IsPreProcessAutoformatTriggerCharacter(typedChar))
         {
             AutoFormat.HandleAutoformat(TextView, typedChar);
         }
     }
     return(base.Invoke(group, id, inputArg, ref outputArg));
 }