Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix boundary condition in StyledText#getTextBounds #1328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4892,7 +4892,7 @@ public Rectangle getTextBounds(int start, int end) {
Rectangle rect;
int y = getLinePixel(lineStart);
int height = 0;
int left = 0x7fffffff, right = 0;
int left = Integer.MAX_VALUE, right = 0;
for (int i = lineStart; i <= lineEnd; i++) {
int lineOffset = content.getOffsetAtLine(i);
TextLayout layout = renderer.getTextLayout(i);
Expand All @@ -4918,6 +4918,9 @@ public Rectangle getTextBounds(int start, int end) {
}
renderer.disposeTextLayout(layout);
}
if (left == Integer.MAX_VALUE) {
left = 0;
}
rect = new Rectangle (left, y, right-left, height);
rect.x += leftMargin - horizontalScrollOffset;
return rect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI(){
text.dispose();
}

@Test
public void test_getTextBounds() {
StyledText text = new StyledText(shell,SWT.BORDER);
try {
text.setText("\r\n\r\ntext");
int firstLineOffset = text.getOffsetAtLine(0);
Rectangle r = text.getTextBounds(firstLineOffset, firstLineOffset);
assertEquals(0,r.x);
assertEquals(0,r.y);
assertEquals(0,r.width);
assertTrue(r.height > 0);

text.setText("\r\n\r\ntext");
int thirdLineOffset = text.getOffsetAtLine(2);
r = text.getTextBounds(thirdLineOffset, thirdLineOffset);
assertEquals(0, r.x);
assertTrue(r.y > 0);
assertTrue(r.width > 0);
assertTrue(r.height > 0);
}finally {
text.dispose();
}
}

@Test
public void test_addExtendedModifyListenerLorg_eclipse_swt_custom_ExtendedModifyListener() {
final String line = "Line1";
Expand Down
Loading