@@ -214,6 +214,71 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
214
214
}
215
215
}
216
216
217
+ protected ( int , int ) FindRangeByIndex ( List < Models . TextDiffLine > lines , int lineIdx )
218
+ {
219
+ var startIdx = - 1 ;
220
+ var endIdx = - 1 ;
221
+
222
+ var normalLineCount = 0 ;
223
+ var modifiedLineCount = 0 ;
224
+
225
+ for ( int i = lineIdx ; i >= 0 ; i -- )
226
+ {
227
+ var line = lines [ i ] ;
228
+ if ( line . Type == Models . TextDiffLineType . Indicator )
229
+ {
230
+ startIdx = i ;
231
+ break ;
232
+ }
233
+
234
+ if ( line . Type == Models . TextDiffLineType . Normal )
235
+ {
236
+ normalLineCount ++ ;
237
+ if ( normalLineCount >= 2 )
238
+ {
239
+ startIdx = i ;
240
+ break ;
241
+ }
242
+ }
243
+ else
244
+ {
245
+ normalLineCount = 0 ;
246
+ modifiedLineCount ++ ;
247
+ }
248
+ }
249
+
250
+ normalLineCount = lines [ lineIdx ] . Type == Models . TextDiffLineType . Normal ? 1 : 0 ;
251
+ for ( int i = lineIdx + 1 ; i < lines . Count ; i ++ )
252
+ {
253
+ var line = lines [ i ] ;
254
+ if ( line . Type == Models . TextDiffLineType . Indicator )
255
+ {
256
+ endIdx = i ;
257
+ break ;
258
+ }
259
+
260
+ if ( line . Type == Models . TextDiffLineType . Normal )
261
+ {
262
+ normalLineCount ++ ;
263
+ if ( normalLineCount >= 2 )
264
+ {
265
+ endIdx = i ;
266
+ break ;
267
+ }
268
+ }
269
+ else
270
+ {
271
+ normalLineCount = 0 ;
272
+ modifiedLineCount ++ ;
273
+ }
274
+ }
275
+
276
+ if ( endIdx == - 1 )
277
+ endIdx = lines . Count - 1 ;
278
+
279
+ return modifiedLineCount > 0 ? ( startIdx , endIdx ) : ( - 1 , - 1 ) ;
280
+ }
281
+
217
282
private void UpdateTextMate ( )
218
283
{
219
284
if ( UseSyntaxHighlighting )
@@ -561,7 +626,7 @@ private void OnTextViewPointerMoved(object sender, PointerEventArgs e)
561
626
return ;
562
627
}
563
628
564
- var ( startIdx , endIdx ) = FindRangeByIndex ( lineIdx ) ;
629
+ var ( startIdx , endIdx ) = FindRangeByIndex ( DiffData . Lines , lineIdx ) ;
565
630
if ( startIdx == - 1 )
566
631
{
567
632
SetCurrentValue ( HighlightChunkProperty , null ) ;
@@ -597,72 +662,6 @@ private void OnTextViewPointerWheelChanged(object sender, PointerWheelEventArgs
597
662
// The offset of TextView has not been updated here. Post a event to next frame.
598
663
Dispatcher . UIThread . Post ( ( ) => OnTextViewPointerMoved ( sender , e ) ) ;
599
664
}
600
-
601
- private ( int , int ) FindRangeByIndex ( int lineIdx )
602
- {
603
- var startIdx = - 1 ;
604
- var endIdx = - 1 ;
605
-
606
- var normalLineCount = 0 ;
607
- var modifiedLineCount = 0 ;
608
-
609
- var lines = DiffData . Lines ;
610
- for ( int i = lineIdx ; i >= 0 ; i -- )
611
- {
612
- var line = lines [ i ] ;
613
- if ( line . Type == Models . TextDiffLineType . Indicator )
614
- {
615
- startIdx = i ;
616
- break ;
617
- }
618
-
619
- if ( line . Type == Models . TextDiffLineType . Normal )
620
- {
621
- normalLineCount ++ ;
622
- if ( normalLineCount >= 2 )
623
- {
624
- startIdx = i ;
625
- break ;
626
- }
627
- }
628
- else
629
- {
630
- normalLineCount = 0 ;
631
- modifiedLineCount ++ ;
632
- }
633
- }
634
-
635
- normalLineCount = lines [ lineIdx ] . Type == Models . TextDiffLineType . Normal ? 1 : 0 ;
636
- for ( int i = lineIdx + 1 ; i < lines . Count ; i ++ )
637
- {
638
- var line = lines [ i ] ;
639
- if ( line . Type == Models . TextDiffLineType . Indicator )
640
- {
641
- endIdx = i ;
642
- break ;
643
- }
644
-
645
- if ( line . Type == Models . TextDiffLineType . Normal )
646
- {
647
- normalLineCount ++ ;
648
- if ( normalLineCount >= 2 )
649
- {
650
- endIdx = i ;
651
- break ;
652
- }
653
- }
654
- else
655
- {
656
- normalLineCount = 0 ;
657
- modifiedLineCount ++ ;
658
- }
659
- }
660
-
661
- if ( endIdx == - 1 )
662
- endIdx = lines . Count - 1 ;
663
-
664
- return modifiedLineCount > 0 ? ( startIdx , endIdx ) : ( - 1 , - 1 ) ;
665
- }
666
665
}
667
666
668
667
public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
@@ -1057,71 +1056,6 @@ private void OnTextViewPointerWheelChanged(object sender, PointerWheelEventArgs
1057
1056
Dispatcher . UIThread . Post ( ( ) => OnTextViewPointerMoved ( sender , e ) ) ;
1058
1057
}
1059
1058
1060
- private ( int , int ) FindRangeByIndex ( List < Models . TextDiffLine > lines , int lineIdx )
1061
- {
1062
- var startIdx = - 1 ;
1063
- var endIdx = - 1 ;
1064
-
1065
- var normalLineCount = 0 ;
1066
- var modifiedLineCount = 0 ;
1067
-
1068
- for ( int i = lineIdx ; i >= 0 ; i -- )
1069
- {
1070
- var line = lines [ i ] ;
1071
- if ( line . Type == Models . TextDiffLineType . Indicator )
1072
- {
1073
- startIdx = i ;
1074
- break ;
1075
- }
1076
-
1077
- if ( line . Type == Models . TextDiffLineType . Normal )
1078
- {
1079
- normalLineCount ++ ;
1080
- if ( normalLineCount >= 2 )
1081
- {
1082
- startIdx = i ;
1083
- break ;
1084
- }
1085
- }
1086
- else
1087
- {
1088
- normalLineCount = 0 ;
1089
- modifiedLineCount ++ ;
1090
- }
1091
- }
1092
-
1093
- normalLineCount = lines [ lineIdx ] . Type == Models . TextDiffLineType . Normal ? 1 : 0 ;
1094
- for ( int i = lineIdx + 1 ; i < lines . Count ; i ++ )
1095
- {
1096
- var line = lines [ i ] ;
1097
- if ( line . Type == Models . TextDiffLineType . Indicator )
1098
- {
1099
- endIdx = i ;
1100
- break ;
1101
- }
1102
-
1103
- if ( line . Type == Models . TextDiffLineType . Normal )
1104
- {
1105
- normalLineCount ++ ;
1106
- if ( normalLineCount >= 2 )
1107
- {
1108
- endIdx = i ;
1109
- break ;
1110
- }
1111
- }
1112
- else
1113
- {
1114
- normalLineCount = 0 ;
1115
- modifiedLineCount ++ ;
1116
- }
1117
- }
1118
-
1119
- if ( endIdx == - 1 )
1120
- endIdx = lines . Count - 1 ;
1121
-
1122
- return modifiedLineCount > 0 ? ( startIdx , endIdx ) : ( - 1 , - 1 ) ;
1123
- }
1124
-
1125
1059
private ScrollViewer _scrollViewer = null ;
1126
1060
}
1127
1061
0 commit comments