@@ -88,18 +88,54 @@ export default class CommandHandler implements vscode.Disposable {
8888 }
8989 }
9090
91+ const conflicts = await this . tracker . getConflicts ( editor . document ) ;
92+
93+ // Still failed to find conflict, warn the user and exit
94+ if ( ! conflicts ) {
95+ vscode . window . showWarningMessage ( localize ( 'cursorNotInConflict' , 'Editor cursor is not within a merge conflict' ) ) ;
96+ return ;
97+ }
98+
9199 const scheme = editor . document . uri . scheme ;
92100 let range = conflict . current . content ;
101+ let leftRanges = conflicts . map ( conflict => [ conflict . current . content , conflict . range ] ) ;
102+ let rightRanges = conflicts . map ( conflict => [ conflict . incoming . content , conflict . range ] ) ;
103+
93104 const leftUri = editor . document . uri . with ( {
94105 scheme : ContentProvider . scheme ,
95- query : JSON . stringify ( { scheme, range } )
106+ query : JSON . stringify ( { scheme, range : range , ranges : leftRanges } )
96107 } ) ;
97108
109+
98110 range = conflict . incoming . content ;
99- const rightUri = leftUri . with ( { query : JSON . stringify ( { scheme, range } ) } ) ;
111+ const rightUri = leftUri . with ( { query : JSON . stringify ( { scheme, ranges : rightRanges } ) } ) ;
112+
113+ let mergeConflictLineOffsets = 0 ;
114+ for ( let nextconflict of conflicts ) {
115+ if ( nextconflict . range . isEqual ( conflict . range ) ) {
116+ break ;
117+ } else {
118+ mergeConflictLineOffsets += ( nextconflict . range . end . line - nextconflict . range . start . line ) - ( nextconflict . incoming . content . end . line - nextconflict . incoming . content . start . line ) ;
119+ }
120+ }
121+ const selection = new vscode . Range (
122+ conflict . range . start . line - mergeConflictLineOffsets , conflict . range . start . character ,
123+ conflict . range . start . line - mergeConflictLineOffsets , conflict . range . start . character
124+ ) ;
100125
101126 const title = localize ( 'compareChangesTitle' , '{0}: Current Changes ⟷ Incoming Changes' , fileName ) ;
102- vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , title ) ;
127+ const mergeConflictConfig = vscode . workspace . getConfiguration ( 'merge-conflict' ) ;
128+ const openToTheSide = mergeConflictConfig . get < string > ( 'diffViewPosition' ) ;
129+ const opts : vscode . TextDocumentShowOptions = {
130+ viewColumn : openToTheSide === 'Beside' ? vscode . ViewColumn . Beside : vscode . ViewColumn . Active ,
131+ selection
132+ } ;
133+
134+ if ( openToTheSide === 'Below' ) {
135+ await vscode . commands . executeCommand ( 'workbench.action.newGroupBelow' ) ;
136+ }
137+
138+ await vscode . commands . executeCommand ( 'vscode.diff' , leftUri , rightUri , title , opts ) ;
103139 }
104140
105141 navigateNext ( editor : vscode . TextEditor ) : Promise < void > {
0 commit comments