From 31735e56b5a5009e115706c59a2e46ac073ffaa7 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Mon, 19 Jan 2026 11:18:52 +0100 Subject: [PATCH] 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. --- .../jface/text/source/MatchingCharacterPainter.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java index f63a54c6c1d6..3e23c79cb3ed 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java @@ -257,17 +257,15 @@ private void draw(final GC gc, final int offset) { if (gc != null) { gc.setForeground(fColor); - final Rectangle bounds= fTextWidget.getTextBounds(offset, offset); + Point offsetLocation= fTextWidget.getLocationAtOffset(offset); - // determine the character width separately, because the getTextBounds above - // will also include any in-line annotations (e.g. codemining annotations) in the width final String matchingCharacter= fTextWidget.getText(offset, offset); - final int width= gc.textExtent(matchingCharacter).x; - - final int height= fTextWidget.getCaret().getSize().y; + Point characterBounds= gc.textExtent(matchingCharacter); + characterBounds.y-= 1; + Rectangle hightlightingArea= Rectangle.of(offsetLocation, characterBounds); // draw box around line segment - gc.drawRectangle(bounds.x, bounds.y + bounds.height - height, width, height - 1); + gc.drawRectangle(hightlightingArea); } else { fTextWidget.redrawRange(offset, 1, true); }