99using GitHub . Commands ;
1010using GitHub . Extensions ;
1111using GitHub . Models ;
12+ using GitHub . ViewModels . GitHubPane ;
1213using GitHub . VisualStudio ;
1314using Microsoft . VisualStudio ;
1415using Microsoft . VisualStudio . Editor ;
1516using Microsoft . VisualStudio . Shell ;
1617using Microsoft . VisualStudio . Shell . Interop ;
1718using Microsoft . VisualStudio . Text ;
19+ using Microsoft . VisualStudio . Text . Editor ;
1820using Microsoft . VisualStudio . Text . Projection ;
1921using Microsoft . VisualStudio . TextManager . Interop ;
2022using Task = System . Threading . Tasks . Task ;
@@ -151,6 +153,9 @@ public async Task OpenDiff(
151153 if ( ! workingDirectory )
152154 {
153155 AddBufferTag ( diffViewer . RightView . TextBuffer , session , rightPath , DiffSide . Right ) ;
156+ EnableNavigateToEditor ( diffViewer . LeftView , session , file ) ;
157+ EnableNavigateToEditor ( diffViewer . RightView , session , file ) ;
158+ EnableNavigateToEditor ( diffViewer . InlineView , session , file ) ;
154159 }
155160
156161 if ( workingDirectory )
@@ -350,6 +355,11 @@ IVsTextView OpenDocument(string fullPath)
350355 return view ;
351356 }
352357
358+ void ShowErrorInStatusBar ( string message )
359+ {
360+ statusBar . ShowMessage ( message ) ;
361+ }
362+
353363 void ShowErrorInStatusBar ( string message , Exception e )
354364 {
355365 statusBar . ShowMessage ( message + ": " + e . Message ) ;
@@ -372,6 +382,54 @@ void AddBufferTag(ITextBuffer buffer, IPullRequestSession session, string path,
372382 }
373383 }
374384
385+ void EnableNavigateToEditor ( IWpfTextView textView , IPullRequestSession session , IPullRequestSessionFile file )
386+ {
387+ var view = vsEditorAdaptersFactory . GetViewAdapter ( textView ) ;
388+ EnableNavigateToEditor ( view , session , file ) ;
389+ }
390+
391+ void EnableNavigateToEditor ( IVsTextView textView , IPullRequestSession session , IPullRequestSessionFile file )
392+ {
393+ var commandGroup = VSConstants . CMDSETID . StandardCommandSet2K_guid ;
394+ var commandId = ( int ) VSConstants . VSStd2KCmdID . RETURN ;
395+ new TextViewCommandDispatcher ( textView , commandGroup , commandId ) . Exec +=
396+ async ( s , e ) => await DoNavigateToEditor ( session , file ) ;
397+
398+ var contextMenuCommandGroup = new Guid ( Guids . guidContextMenuSetString ) ;
399+ var goToCommandId = PkgCmdIDList . openFileInSolutionCommand ;
400+ new TextViewCommandDispatcher ( textView , contextMenuCommandGroup , goToCommandId ) . Exec +=
401+ async ( s , e ) => await DoNavigateToEditor ( session , file ) ;
402+ }
403+
404+ async Task DoNavigateToEditor ( IPullRequestSession session , IPullRequestSessionFile file )
405+ {
406+ try
407+ {
408+ if ( ! session . IsCheckedOut )
409+ {
410+ ShowInfoMessage ( "Checkout PR branch before opening file in solution." ) ;
411+ return ;
412+ }
413+
414+ var fullPath = GetAbsolutePath ( session , file ) ;
415+
416+ var activeView = FindActiveView ( ) ;
417+ if ( activeView == null )
418+ {
419+ ShowErrorInStatusBar ( "Couldn't find active view" ) ;
420+ return ;
421+ }
422+
423+ NavigateToEquivalentPosition ( activeView , fullPath ) ;
424+
425+ await usageTracker . IncrementCounter ( x => x . NumberOfPRDetailsNavigateToEditor ) ;
426+ }
427+ catch ( Exception e )
428+ {
429+ ShowErrorInStatusBar ( "Error navigating to editor" , e ) ;
430+ }
431+ }
432+
375433 async Task < string > ExtractFile ( IPullRequestSession session , IPullRequestSessionFile file , bool head )
376434 {
377435 var encoding = pullRequestService . GetEncoding ( session . LocalRepository , file . RelativePath ) ;
@@ -424,6 +482,13 @@ async Task<string> GetBaseFileName(IPullRequestSession session, IPullRequestSess
424482 }
425483 }
426484
485+ void ShowInfoMessage ( string message )
486+ {
487+ ErrorHandler . ThrowOnFailure ( VsShellUtilities . ShowMessageBox (
488+ serviceProvider , message , null ,
489+ OLEMSGICON . OLEMSGICON_INFO , OLEMSGBUTTON . OLEMSGBUTTON_OK , OLEMSGDEFBUTTON . OLEMSGDEFBUTTON_FIRST ) ) ;
490+ }
491+
427492 static string GetAbsolutePath ( IPullRequestSession session , IPullRequestSessionFile file )
428493 {
429494 return Path . Combine ( session . LocalRepository . LocalPath , file . RelativePath ) ;
0 commit comments