Skip to content

Commit 0badc89

Browse files
ShahzaibIbrahimakoch-yatta
authored andcommitted
Create more precise highlight brackets
This commit addresses too small or wrongly placed highlight brackets especisally on windows. Because of rounding errors the bracket selection highlight is often inconsistent. Making use of residual values plus simplifying the logic provides better rectangle values and the highlight is more consistent across all zooms.
1 parent 740f6fc commit 0badc89

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,15 @@ private void draw(final GC gc, final int offset) {
257257
if (gc != null) {
258258
gc.setForeground(fColor);
259259

260-
final Rectangle bounds= fTextWidget.getTextBounds(offset, offset);
260+
Point offsetLocation= fTextWidget.getLocationAtOffset(offset);
261261

262-
// determine the character width separately, because the getTextBounds above
263-
// will also include any in-line annotations (e.g. codemining annotations) in the width
264262
final String matchingCharacter= fTextWidget.getText(offset, offset);
265-
final int width= gc.textExtent(matchingCharacter).x;
266-
267-
final int height= fTextWidget.getCaret().getSize().y;
263+
Point characterBounds= gc.textExtent(matchingCharacter);
264+
characterBounds.y-= 1;
265+
Rectangle hightlightingArea= Rectangle.of(offsetLocation, characterBounds);
268266

269267
// draw box around line segment
270-
gc.drawRectangle(bounds.x, bounds.y + bounds.height - height, width, height - 1);
268+
gc.drawRectangle(hightlightingArea);
271269
} else {
272270
fTextWidget.redrawRange(offset, 1, true);
273271
}

0 commit comments

Comments
 (0)