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

            textView.TextBuffer.Changed += (object sender, TextContentChangedEventArgs e) => {
                List <TextChangeEventArgs> textChanges = TextUtility.ConvertToRelative(e);
                ast.ReflectTextChanges(textChanges);

                if (e.Changes[0].NewText.Length == 1)
                {
                    char ch = e.Changes[0].NewText[0];
                    if (AutoFormat.IsAutoformatTriggerCharacter(ch))
                    {
                        int offset = 0;
                        if (e.Changes[0].NewText[0].IsLineBreak())
                        {
                            position = e.Changes[0].OldPosition + 1;
                            textView.Caret.MoveTo(new SnapshotPoint(e.After, position));
                            offset = -1;
                        }
                        FormatOperations.FormatLine(textView, textView.TextBuffer, ast, offset);
                    }
                }
                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, textToType);

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

                base.PostProcessInvoke(result, group, id, inputArg, ref outputArg);
            }
        }