From 76a8f91dc4a1a620eb8ccc730753d0e4ff784eb3 Mon Sep 17 00:00:00 2001 From: Aaron Bockover Date: Thu, 12 Sep 2019 17:32:34 -0400 Subject: Sync with vs-editor-core@28bf8d91 --- .../Text/Def/TextUI/Commanding/CommandSelector.cs | 12 +++ .../NavigateToNextErrorInDocumentCommandArgs.cs | 21 +++++ ...NavigateToPreviousErrorInDocumentCommandArgs.cs | 21 +++++ .../Commands/NavigateToNextIssueCommandHandler.cs | 92 ++++++++++++++-------- 4 files changed, 115 insertions(+), 31 deletions(-) create mode 100644 src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToNextErrorInDocumentCommandArgs.cs create mode 100644 src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToPreviousErrorInDocumentCommandArgs.cs diff --git a/src/Editor/Text/Def/TextUI/Commanding/CommandSelector.cs b/src/Editor/Text/Def/TextUI/Commanding/CommandSelector.cs index 91e2050..17e771c 100644 --- a/src/Editor/Text/Def/TextUI/Commanding/CommandSelector.cs +++ b/src/Editor/Text/Def/TextUI/Commanding/CommandSelector.cs @@ -291,6 +291,18 @@ namespace Microsoft.VisualStudio.Text.Editor.Commanding /// ⇧⌥⇣ public const string ContractSelection = "contractSelection:"; + /// ⌥⇡ + public const string NavigateToPreviousIssueInDocument = "navigateToPreviousIssueInDocument:"; + + /// ⌥⇣ + public const string NavigateToNextIssueInDocument = "navigateToNextIssueInDocument:"; + + /// ⌘⌥⇡ + public const string NavigateToPreviousErrorInDocument = "navigateToPreviousErrorInDocument:"; + + /// ⌘⌥⇣ + public const string NavigateToNextErrorInDocument = "navigateToNextErrorInDocument:"; + #endregion } diff --git a/src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToNextErrorInDocumentCommandArgs.cs b/src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToNextErrorInDocumentCommandArgs.cs new file mode 100644 index 0000000..2039755 --- /dev/null +++ b/src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToNextErrorInDocumentCommandArgs.cs @@ -0,0 +1,21 @@ +namespace Microsoft.VisualStudio.Text.Editor.Commanding.Commands +{ + using Microsoft.VisualStudio.Text.Adornments; + + /// + /// for next error command. + /// + public sealed class NavigateToNextErrorInDocumentCommandArgs : ErrorCommandArgsBase + { + /// + /// Creates an instance of with a list + /// that contains only errors (exlucdes hinted suggestions and warnings). + /// + /// The upon which to invoke the command. + /// The upon which to invoke the command. + public NavigateToNextErrorInDocumentCommandArgs(ITextView textView, ITextBuffer subjectBuffer) + : base(textView, subjectBuffer, new [] { PredefinedErrorTypeNames.CompilerError, PredefinedErrorTypeNames.OtherError, PredefinedErrorTypeNames.SyntaxError }) + { + } + } +} diff --git a/src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToPreviousErrorInDocumentCommandArgs.cs b/src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToPreviousErrorInDocumentCommandArgs.cs new file mode 100644 index 0000000..fb65d83 --- /dev/null +++ b/src/Editor/Text/Def/TextUI/Commanding/Commands/NavigateToPreviousErrorInDocumentCommandArgs.cs @@ -0,0 +1,21 @@ +namespace Microsoft.VisualStudio.Text.Editor.Commanding.Commands +{ + using Microsoft.VisualStudio.Text.Adornments; + + /// + /// for next error command. + /// + public sealed class NavigateToPreviousErrorInDocumentCommandArgs : ErrorCommandArgsBase + { + /// + /// Creates an instance of with a list + /// that contains only errors (exlucdes hinted suggestions and warnings). + /// + /// The upon which to invoke the command. + /// The upon which to invoke the command. + public NavigateToPreviousErrorInDocumentCommandArgs(ITextView textView, ITextBuffer subjectBuffer) + : base(textView, subjectBuffer, new [] { PredefinedErrorTypeNames.CompilerError, PredefinedErrorTypeNames.OtherError, PredefinedErrorTypeNames.SyntaxError }) + { + } + } +} \ No newline at end of file diff --git a/src/Editor/Text/Impl/EditorOperations/Commands/NavigateToNextIssueCommandHandler.cs b/src/Editor/Text/Impl/EditorOperations/Commands/NavigateToNextIssueCommandHandler.cs index 25948cf..3b51151 100644 --- a/src/Editor/Text/Impl/EditorOperations/Commands/NavigateToNextIssueCommandHandler.cs +++ b/src/Editor/Text/Impl/EditorOperations/Commands/NavigateToNextIssueCommandHandler.cs @@ -15,18 +15,18 @@ [Name("default " + nameof(NavigateToNextIssueCommandHandler))] [ContentType("any")] [TextViewRole(PredefinedTextViewRoles.Analyzable)] - internal sealed class NavigateToNextIssueCommandHandler : ICommandHandler, ICommandHandler + internal sealed class NavigateToNextIssueCommandHandler : + ICommandHandler, + ICommandHandler, + ICommandHandler, + ICommandHandler { [Import] private Lazy tagAggregatorFactoryService; public string DisplayName => Strings.NextIssue; - #region Previous Issue - - public CommandState GetCommandState(NavigateToPreviousIssueInDocumentCommandArgs args) => CommandState.Available; - - public bool ExecuteCommand(NavigateToPreviousIssueInDocumentCommandArgs args, CommandExecutionContext executionContext) + private bool NavigateToNextIssue(ErrorCommandArgsBase args, CommandExecutionContext executionContext) { var snapshot = args.TextView.TextSnapshot; var spans = this.GetTagSpansCollection(snapshot, args.ErrorTagTypeNames); @@ -38,17 +38,24 @@ (int indexOfErrorSpan, bool containsPoint) = IndexOfTagSpanNearPoint(spans, args.TextView.Caret.Position.BufferPosition.Position); - int nextIndex = indexOfErrorSpan - 1; - if (containsPoint && (spans.Count == 1)) + int nextIndex = indexOfErrorSpan + 1; + if (containsPoint) { - // There is only one error tag and it contains the caret. Ensure it stays put. - return true; + if (spans.Count == 1) + { + // There is only one error tag and it contains the caret. Ensure it stays put. + return true; + } + } + else + { + nextIndex = indexOfErrorSpan; } // Wrap if needed. - if (nextIndex < 0) + if ((indexOfErrorSpan == -1) || (nextIndex >= spans.Count)) { - nextIndex = (spans.Count - 1); + nextIndex = 0; } args.TextView.Caret.MoveTo(new SnapshotPoint(snapshot, spans[nextIndex].Start)); @@ -56,12 +63,7 @@ return true; } - #endregion - - #region Next Issue - public CommandState GetCommandState(NavigateToNextIssueInDocumentCommandArgs args) => CommandState.Available; - - public bool ExecuteCommand(NavigateToNextIssueInDocumentCommandArgs args, CommandExecutionContext executionContext) + private bool NavigateToPreviousIssue(ErrorCommandArgsBase args, CommandExecutionContext executionContext) { var snapshot = args.TextView.TextSnapshot; var spans = this.GetTagSpansCollection(snapshot, args.ErrorTagTypeNames); @@ -73,24 +75,17 @@ (int indexOfErrorSpan, bool containsPoint) = IndexOfTagSpanNearPoint(spans, args.TextView.Caret.Position.BufferPosition.Position); - int nextIndex = indexOfErrorSpan + 1; - if (containsPoint) - { - if (spans.Count == 1) - { - // There is only one error tag and it contains the caret. Ensure it stays put. - return true; - } - } - else + int nextIndex = indexOfErrorSpan - 1; + if (containsPoint && (spans.Count == 1)) { - nextIndex = indexOfErrorSpan; + // There is only one error tag and it contains the caret. Ensure it stays put. + return true; } // Wrap if needed. - if ((indexOfErrorSpan == -1) || (nextIndex >= spans.Count)) + if (nextIndex < 0) { - nextIndex = 0; + nextIndex = (spans.Count - 1); } args.TextView.Caret.MoveTo(new SnapshotPoint(snapshot, spans[nextIndex].Start)); @@ -98,6 +93,41 @@ return true; } + #region Previous Issue + public CommandState GetCommandState(NavigateToPreviousIssueInDocumentCommandArgs args) => CommandState.Available; + + public bool ExecuteCommand(NavigateToPreviousIssueInDocumentCommandArgs args, CommandExecutionContext executionContext) + { + return NavigateToPreviousIssue(args, executionContext); + } + #endregion + + #region Next Issue + public CommandState GetCommandState(NavigateToNextIssueInDocumentCommandArgs args) => CommandState.Available; + + public bool ExecuteCommand(NavigateToNextIssueInDocumentCommandArgs args, CommandExecutionContext executionContext) + { + return NavigateToNextIssue(args, executionContext); + } + #endregion + + + #region Next Error + public CommandState GetCommandState(NavigateToNextErrorInDocumentCommandArgs args) => CommandState.Available; + + public bool ExecuteCommand(NavigateToNextErrorInDocumentCommandArgs args, CommandExecutionContext executionContext) + { + return NavigateToNextIssue(args, executionContext); + } + #endregion + + #region Prev Error + public CommandState GetCommandState(NavigateToPreviousErrorInDocumentCommandArgs args) => CommandState.Available; + + public bool ExecuteCommand(NavigateToPreviousErrorInDocumentCommandArgs args, CommandExecutionContext executionContext) + { + return NavigateToPreviousIssue(args, executionContext); + } #endregion private static (int index, bool containsPoint) IndexOfTagSpanNearPoint(NormalizedSpanCollection spans, int point) -- cgit v1.2.3