private ITextView TestAutoFormat(int position, string initialContent = "") { var editorView = TextViewTest.MakeTextView(initialContent, position, out AstRoot ast); var textView = editorView.As <ITextView>(); var af = new VsAutoFormat(_services, textView); textView.TextBuffer.Changed += (s, e) => { var tc = e.ToTextChange(); ast.ReflectTextChange(tc.Start, tc.OldLength, tc.NewLength, tc.NewTextProvider); if (e.Changes[0].NewText.Length == 1) { var ch = e.Changes[0].NewText[0]; if (af.IsPostProcessAutoformatTriggerCharacter(ch)) { position = e.Changes[0].OldPosition + 1; textView.Caret.MoveTo(new SnapshotPoint(e.After, position)); var fo = new FormatOperations(_services, editorView, editorView.EditorBuffer); fo.FormatViewLine(-1); } } else { var 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); }
public RTypingCommandHandler(ITextView textView, IServiceContainer services) : base(textView) { _services = services; _autoFormat = new VsAutoFormat(services, textView); }