@@ -2251,7 +2251,7 @@ private Diff handleMouseInSides(Canvas canvas, MergeSourceViewer tp, int my) {
2251
2251
return null ;
2252
2252
2253
2253
if (fMerger .hasChanges ()) {
2254
- int shift = tp . getVerticalScrollOffset ( ) + (2 - LW );
2254
+ int shift = calculateShift ( tp ) + (2 - LW );
2255
2255
2256
2256
Point region = new Point (0 , 0 );
2257
2257
char leg = getLeg (tp );
@@ -2264,6 +2264,7 @@ private Diff handleMouseInSides(Canvas canvas, MergeSourceViewer tp, int my) {
2264
2264
continue ;
2265
2265
2266
2266
tp .getLineRange (diff .getPosition (leg ), region );
2267
+ region .x -= tp .getDocumentRegionOffset ();
2267
2268
int y = getHeightBetweenLines (tp , 0 , region .x ) + shift ;
2268
2269
int h = getHeightBetweenLines (tp , region .x , region .x + region .y );
2269
2270
@@ -2293,8 +2294,8 @@ private Diff getDiffUnderMouse(Canvas canvas, int mx, int my, Rectangle r) {
2293
2294
return null ;
2294
2295
2295
2296
if (fMerger .hasChanges ()) {
2296
- int lshift = fLeft . getVerticalScrollOffset ( );
2297
- int rshift = fRight . getVerticalScrollOffset ( );
2297
+ int lshift = calculateShift ( fLeft );
2298
+ int rshift = calculateShift ( fRight );
2298
2299
2299
2300
Point region = new Point (0 , 0 );
2300
2301
@@ -2307,10 +2308,12 @@ private Diff getDiffUnderMouse(Canvas canvas, int mx, int my, Rectangle r) {
2307
2308
continue ;
2308
2309
2309
2310
fLeft .getLineRange (diff .getPosition (LEFT_CONTRIBUTOR ), region );
2311
+ region .x -= fLeft .getDocumentRegionOffset ();
2310
2312
int ly = getHeightBetweenLines (fLeft , 0 , region .x ) + lshift ;
2311
2313
int lh = getHeightBetweenLines (fLeft , region .x , region .x + region .y );
2312
2314
2313
2315
fRight .getLineRange (diff .getPosition (RIGHT_CONTRIBUTOR ), region );
2316
+ region .x -= fRight .getDocumentRegionOffset ();
2314
2317
int ry = getHeightBetweenLines (fRight , 0 , region .x ) + rshift ;
2315
2318
int rh = getHeightBetweenLines (fRight , region .x , region .x + region .y );
2316
2319
@@ -4222,6 +4225,9 @@ private void updateLines(IDocument d) {
4222
4225
* @return
4223
4226
*/
4224
4227
private int getHeightBetweenLines (MergeSourceViewer tp , int fromLine , int toLine ) {
4228
+
4229
+ if (fromLine == toLine )
4230
+ return 0 ;
4225
4231
StyledText w = tp .getSourceViewer ().getTextWidget ();
4226
4232
List <Integer > lineHeights = this .lineHeightsByViewer .get (tp );
4227
4233
if (lineHeights == null ) {
@@ -4236,7 +4242,16 @@ private int getHeightBetweenLines(MergeSourceViewer tp, int fromLine, int toLine
4236
4242
}
4237
4243
});
4238
4244
}
4245
+
4239
4246
int lineSpacing = w .getLineSpacing ();
4247
+
4248
+ // If the linenumber is higher than the number of lines, we should prevent an
4249
+ // IndexOutOfBoundsException
4250
+ if (toLine > w .getLineCount ()){
4251
+ int lineHeight = tp .getSourceViewer ().getTextWidget ().getLineHeight ();
4252
+ return (toLine - fromLine ) * (lineHeight + w .getLineVerticalIndent (0 )) + lineSpacing ;
4253
+ }
4254
+
4240
4255
int height = 0 ;
4241
4256
for (int i = fromLine ; i < toLine ; i ++) {
4242
4257
Integer heightAtLine = lineHeights .get (i );
@@ -4317,8 +4332,8 @@ private void paintCenter(Canvas canvas, GC g) {
4317
4332
return ;
4318
4333
4319
4334
if (fMerger .hasChanges ()) {
4320
- int lshift = fLeft . getVerticalScrollOffset ( );
4321
- int rshift = fRight . getVerticalScrollOffset ( );
4335
+ int lshift = calculateShift ( fLeft );
4336
+ int rshift = calculateShift ( fRight );
4322
4337
4323
4338
Point region = new Point (0 , 0 );
4324
4339
@@ -4332,10 +4347,12 @@ private void paintCenter(Canvas canvas, GC g) {
4332
4347
continue ;
4333
4348
4334
4349
fLeft .getLineRange (diff .getPosition (LEFT_CONTRIBUTOR ), region );
4350
+ region .x -= fLeft .getDocumentRegionOffset ();
4335
4351
int ly = getHeightBetweenLines (fLeft , 0 , region .x ) + lshift ;
4336
4352
int lh = getHeightBetweenLines (fLeft , region .x , region .x + region .y );
4337
4353
4338
4354
fRight .getLineRange (diff .getPosition (RIGHT_CONTRIBUTOR ), region );
4355
+ region .x -= fRight .getDocumentRegionOffset ();
4339
4356
int ry = getHeightBetweenLines (fRight , 0 , region .x ) + rshift ;
4340
4357
int rh = getHeightBetweenLines (fRight , region .x , region .x + region .y );
4341
4358
@@ -4436,6 +4453,10 @@ private void buildBaseCenterCurve(int w) {
4436
4453
}
4437
4454
}
4438
4455
4456
+ private int calculateShift (MergeSourceViewer tp ) {
4457
+ return tp .getSourceViewer ().getTopInset () - tp .getSourceViewer ().getTextWidget ().getTopPixel ();
4458
+ }
4459
+
4439
4460
private void paintSides (GC g , MergeSourceViewer tp , Canvas canvas , boolean right ) {
4440
4461
4441
4462
Display display = canvas .getDisplay ();
@@ -4462,7 +4483,7 @@ private void paintSides(GC g, MergeSourceViewer tp, Canvas canvas, boolean right
4462
4483
4463
4484
if (fMerger .hasChanges ()) {
4464
4485
boolean allOutgoing = allOutgoing ();
4465
- int shift = tp . getVerticalScrollOffset ( ) + (2 - LW );
4486
+ int shift = calculateShift ( tp ) + (2 - LW );
4466
4487
4467
4488
Point region = new Point (0 , 0 );
4468
4489
char leg = getLeg (tp );
@@ -4475,6 +4496,7 @@ private void paintSides(GC g, MergeSourceViewer tp, Canvas canvas, boolean right
4475
4496
continue ;
4476
4497
4477
4498
tp .getLineRange (diff .getPosition (leg ), region );
4499
+ region .x -= tp .getDocumentRegionOffset ();
4478
4500
int y = getHeightBetweenLines (tp , 0 , region .x ) + shift ;
4479
4501
int h = getHeightBetweenLines (tp , region .x , region .x + region .y );
4480
4502
@@ -4522,7 +4544,7 @@ private void paint(PaintEvent event, MergeSourceViewer tp) {
4522
4544
Display display = canvas .getDisplay ();
4523
4545
4524
4546
int w = canvas .getSize ().x ;
4525
- int shift = tp . getVerticalScrollOffset ( ) + (2 - LW );
4547
+ int shift = calculateShift ( tp ) + (2 - LW );
4526
4548
int maxh = event .y +event .height ; // visibleHeight
4527
4549
4528
4550
shift += fTopInset ;
@@ -4540,6 +4562,7 @@ private void paint(PaintEvent event, MergeSourceViewer tp) {
4540
4562
continue ;
4541
4563
4542
4564
tp .getLineRange (diff .getPosition (leg ), range );
4565
+ range .x -= tp .getDocumentRegionOffset ();
4543
4566
int y = getHeightBetweenLines (tp , 0 , range .x ) + shift ;
4544
4567
int h = getHeightBetweenLines (tp , range .x , range .x + range .y );
4545
4568
0 commit comments