eclipse-platform / eclipse.platform.text

8 stars 45 forks source link

brackets highlighting should not contains code mining text #47 #181

Closed arihunta closed 1 year ago

arihunta commented 1 year ago

Notes

MatchingCharacterPainter is using the StyledText.getTextBounds() method to determine the width of the highlight box to draw. This method calculates width based on runs of text, and thus includes the method parameter hints in that width.

This change instead moves to using GC.textExtent() to determine the width of text to highlight, ensuring that only the desired character is highlighted. The character width to highlight was already hard-coded to 1, so now we just pull a single character of text from the desired offset, and pass it to GC.textExtent() to get its width.

Testing

Manual testing

Tested on Windows, running in a normal window

image

Tested on Windows, on a desktop with 200% font scaling enabled:

image

Unit testing

I didn't find existing unit tests for MatchingCharacterPainter, and am not quite sure how one would implement such, though I'm very open to suggestions.

mickaelistria commented 1 year ago

Thanks for this good patch!