Improve accuracy to colorize matches#570
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the accuracy of text measurement when colorizing search matches in the result list by replacing GetTextExtentPoint32 with DrawTextEx using the DT_CALCRECT flag. This addresses issue #569 where match highlighting was not precisely aligned with the actual text.
Key Changes
- Replaced
GetTextExtentPoint32API calls withDrawTextExusingDT_CALCRECTflag for more accurate text width calculations - Reorganized variable declarations to reuse
RECT rc2andLONG widththroughout the function - Updated comment to reflect the accuracy issue with
GetTextExtentPoint32
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (rc.left >= rc.right) | ||
| { | ||
| break; | ||
| } |
There was a problem hiding this comment.
The rc2 rectangle is being reused without resetting it to {0, 0, 0, 0} after the first DrawTextEx call on line 2726. When DrawTextEx is called with DT_CALCRECT, it modifies the RECT structure. This second call may produce incorrect results because rc2 already contains non-zero values from the first call.
Consider resetting rc2 before the second DrawTextEx call:
rc2 = {0, 0, 0, 0};
DrawTextEx(hdc, pMatch, pInfo->matchLengths[subIndex], &rc2, DT_CALCRECT | DT_NOPREFIX | DT_SINGLELINE, NULL);| } | |
| } | |
| rc2 = {0, 0, 0, 0}; |
|
Thanks! |
Fix #569.