From cf768801e74c0815d73f2e446b37fcf5a5dd1c80 Mon Sep 17 00:00:00 2001 From: Kevin Pilch-Bisson Date: Tue, 27 Oct 2015 11:25:58 -0700 Subject: [PATCH] Extract a helper method --- ...GoToNextAndPreviousMethodCommandHandler.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/EditorFeatures/Core/CommandHandlers/GoToNextAndPreviousMethodCommandHandler.cs b/src/EditorFeatures/Core/CommandHandlers/GoToNextAndPreviousMethodCommandHandler.cs index 74010835cb7..5f420c515ef 100644 --- a/src/EditorFeatures/Core/CommandHandlers/GoToNextAndPreviousMethodCommandHandler.cs +++ b/src/EditorFeatures/Core/CommandHandlers/GoToNextAndPreviousMethodCommandHandler.cs @@ -46,34 +46,31 @@ public void ExecuteCommand(GoToPreviousMethodCommandArgs args, Action nextHandle private static CommandState GetCommandState(ITextBuffer subjectBuffer, ITextView textView, Func nextHandler) { var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); + var caretPoint = textView.GetCaretPoint(subjectBuffer); + return IsAvailable(document, caretPoint) ? CommandState.Available : nextHandler(); + } + + private static bool IsAvailable(Document document, SnapshotPoint? caretPoint) + { var documentSupportsSuggestionService = document.Project.Solution.Workspace.Services.GetService(); if (document == null || !document.SupportsSyntaxTree || !documentSupportsSuggestionService.SupportsNavigationToAnyPosition(document)) { - return nextHandler(); + return false; } - var caretPoint = textView.GetCaretPoint(subjectBuffer); if (!caretPoint.HasValue) { - return nextHandler(); + return false; } - return CommandState.Available; + return true; } - private void ExecuteCommand(Action nextHandler, ITextBuffer subjectBuffer, ITextView textView, bool next) { var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - var documentSupportsSuggestionService = document.Project.Solution.Workspace.Services.GetService(); - if (document == null || !document.SupportsSyntaxTree || !documentSupportsSuggestionService.SupportsNavigationToAnyPosition(document)) - { - nextHandler(); - return; - } - var caretPoint = textView.GetCaretPoint(subjectBuffer); - if (!caretPoint.HasValue) + if (!IsAvailable(document, caretPoint)) { nextHandler(); return; -- GitLab