@@ -223,7 +223,7 @@ public override TextDiffContext SwitchMode()
223223 return new CombinedTextDiff ( _option , _data , this ) ;
224224 }
225225
226- public void ConvertsToCombinedRange ( ref int startLine , ref int endLine , bool isOldSide )
226+ public void GetCombinedRangeForSingleSide ( ref int startLine , ref int endLine , bool isOldSide )
227227 {
228228 endLine = Math . Min ( endLine , _data . Lines . Count - 1 ) ;
229229
@@ -262,6 +262,32 @@ public void ConvertsToCombinedRange(ref int startLine, ref int endLine, bool isO
262262 endLine = _data . Lines . IndexOf ( endContent ) ;
263263 }
264264
265+ public void GetCombinedRangeForBothSides ( ref int startLine , ref int endLine , bool isOldSide )
266+ {
267+ var fromSide = isOldSide ? Old : New ;
268+ endLine = Math . Min ( endLine , fromSide . Count - 1 ) ;
269+
270+ // Since this function is only used for auto-detected hunk, we just need to find out the a first changed line
271+ // and then use `FindRangeByIndex` to get the range of hunk.
272+ for ( int i = startLine ; i <= endLine ; i ++ )
273+ {
274+ var line = fromSide [ i ] ;
275+ if ( line . Type == Models . TextDiffLineType . Added || line . Type == Models . TextDiffLineType . Deleted )
276+ {
277+ ( startLine , endLine ) = FindRangeByIndex ( _data . Lines , _data . Lines . IndexOf ( line ) ) ;
278+ return ;
279+ }
280+
281+ if ( line . Type == Models . TextDiffLineType . None )
282+ {
283+ var otherSide = isOldSide ? New : Old ;
284+ var changedLine = otherSide [ i ] ; // Find the changed line on the other side in the same position
285+ ( startLine , endLine ) = FindRangeByIndex ( _data . Lines , _data . Lines . IndexOf ( changedLine ) ) ;
286+ return ;
287+ }
288+ }
289+ }
290+
265291 private void FillEmptyLines ( )
266292 {
267293 if ( Old . Count < New . Count )
0 commit comments