@@ -119,6 +119,54 @@ async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
119119 }
120120 }
121121
122+ async Task DoOpenLiveFile ( IPullRequestFileNode file )
123+ {
124+ try
125+ {
126+ var activeView = FindActiveView ( ) ;
127+ if ( activeView == null )
128+ {
129+ ShowErrorInStatusBar ( "Couldn't find active view" ) ;
130+ return ;
131+ }
132+
133+ int line ;
134+ int column ;
135+ activeView . GetCaretPos ( out line , out column ) ;
136+
137+ var fullPath = ViewModel . GetLocalFilePath ( file ) ;
138+ IVsTextView view = OpenDocument ( fullPath ) ;
139+
140+ view . SetCaretPos ( line , column ) ;
141+
142+ // TODO: Add metrics for NumberOfPRDetailsOpenLiveFile
143+ await UsageTracker . IncrementCounter ( x => x . NumberOfPRDetailsOpenFileInSolution ) ;
144+ }
145+ catch ( Exception e )
146+ {
147+ ShowErrorInStatusBar ( "Error opening live file" , e ) ;
148+ }
149+ }
150+
151+ static IVsTextView OpenDocument ( string fullPath )
152+ {
153+ var logicalView = VSConstants . LOGVIEWID . TextView_guid ;
154+ IVsUIHierarchy hierarchy ;
155+ uint itemID ;
156+ IVsWindowFrame windowFrame ;
157+ IVsTextView view ;
158+ VsShellUtilities . OpenDocument ( Services . GitHubServiceProvider , fullPath , logicalView , out hierarchy , out itemID , out windowFrame , out view ) ;
159+ return view ;
160+ }
161+
162+ static IVsTextView FindActiveView ( )
163+ {
164+ var textManager = Services . GitHubServiceProvider . GetService < SVsTextManager , IVsTextManager2 > ( ) ;
165+ IVsTextView view ;
166+ var hresult = textManager . GetActiveView2 ( 1 , null , ( uint ) _VIEWFRAMETYPE . vftCodeWindow , out view ) ;
167+ return hresult == VSConstants . S_OK ? view : null ;
168+ }
169+
122170 async Task DoDiffFile ( IPullRequestFileNode file , bool workingDirectory )
123171 {
124172 try
@@ -201,15 +249,19 @@ void EnableNavigateToEditor(IWpfTextView textView, IPullRequestFileNode file)
201249 {
202250 textView . VisualElement . PreviewKeyDown += async ( s , e ) =>
203251 {
204- await DoOpenFile ( file , true ) ;
252+ await DoOpenLiveFile ( file ) ;
205253 e . Handled = true ;
206254 } ;
207255 }
208256
209- void ShowErrorInStatusBar ( string message , Exception e )
257+ void ShowErrorInStatusBar ( string message , Exception e = null )
210258 {
211259 var ns = GitHub . VisualStudio . Services . DefaultExportProvider . GetExportedValue < IStatusBarNotificationService > ( ) ;
212- ns ? . ShowMessage ( message + ": " + e . Message ) ;
260+ if ( e != null )
261+ {
262+ message += ": " + e . Message ;
263+ }
264+ ns ? . ShowMessage ( message ) ;
213265 }
214266
215267 void FileListMouseDoubleClick ( object sender , MouseButtonEventArgs e )
0 commit comments