Skip to content

Comments

Improve accuracy to colorize matches#570

Merged
stefankueng merged 1 commit intostefankueng:mainfrom
lifenjoiner:MatchPos
Nov 26, 2025
Merged

Improve accuracy to colorize matches#570
stefankueng merged 1 commit intostefankueng:mainfrom
lifenjoiner:MatchPos

Conversation

@lifenjoiner
Copy link
Collaborator

Fix #569.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetTextExtentPoint32 API calls with DrawTextEx using DT_CALCRECT flag for more accurate text width calculations
  • Reorganized variable declarations to reuse RECT rc2 and LONG width throughout 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;
}
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Suggested change
}
}
rc2 = {0, 0, 0, 0};

Copilot uses AI. Check for mistakes.
@stefankueng stefankueng merged commit ce4eb3b into stefankueng:main Nov 26, 2025
8 checks passed
@stefankueng
Copy link
Owner

Thanks!

@lifenjoiner lifenjoiner deleted the MatchPos branch November 27, 2025 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

substring highlighting a bit off to the right at contents list

2 participants