public bool ExecuteCommand(GotoBraceCommandArgs args, VSCommanding.CommandExecutionContext executionContext) { var snapshot = args.SubjectBuffer.CurrentSnapshot; var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); var caretPosition = args.TextView.Caret.Position.BufferPosition.Position; var task = _braceMatchingService.FindMatchingSpanAsync(document, caretPosition, executionContext.OperationContext.UserCancellationToken); var span = task.WaitAndGetResult(executionContext.OperationContext.UserCancellationToken); if (!span.HasValue) { return(false); } if (span.Value.Start < caretPosition) { args.TextView.TryMoveCaretToAndEnsureVisible(args.SubjectBuffer.CurrentSnapshot.GetPoint(span.Value.Start)); } else if (span.Value.End > caretPosition) { args.TextView.TryMoveCaretToAndEnsureVisible(args.SubjectBuffer.CurrentSnapshot.GetPoint(span.Value.End)); } return(true); }
public bool ExecuteCommand(TypeCharCommandArgs args, VSCommanding.CommandExecutionContext executionContext) { if (args.TypedChar == '/') { var caret = args.TextView.GetCaretPoint(args.SubjectBuffer); if (caret != null) { var(snapshot, position) = caret.Value; // Check that the line is all whitespace ending with an asterisk and a single space (| marks caret position): // * | if (position >= 2 && snapshot[position - 1] == ' ' && snapshot[position - 2] == '*') { var line = snapshot.GetLineFromPosition(position); if (line.End == position && line.IsEmptyOrWhitespace(0, line.Length - 2)) { if (args.SubjectBuffer.GetFeatureOnOffOption(FeatureOnOffOptions.AutoInsertBlockCommentStartString) && BlockCommentEditingCommandHandler.IsCaretInsideBlockCommentSyntax(caret.Value)) { args.SubjectBuffer.Replace(new VisualStudio.Text.Span(position - 1, 1), "/"); return(true); } } } } } return(false); }
public bool ExecuteCommand(VSEditorCommands.ReturnKeyCommandArgs args, VSCommanding.CommandExecutionContext context) { return(TryHandleReturnKey(args.SubjectBuffer, args.TextView)); }