Fix full preview in Inspect image matches#10566
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes OCR “Inspect image matches” (and related additions/history flows) so grouped matches (where ExpandCount > 1) render and highlight using the full combined bitmap/bounds rather than only the first split segment.
Changes:
- Preserve full
NOcrCharmetadata (width/height/margins/lines +ExpandCount) when building the inspect match list. - Update nOCR and Binary OCR inspect view models to track a separate “display” bitmap/bounds/top-margin for grouped matches via
ExpandedOcrGroup. - Store the combined preview bitmap (and top margin for Binary OCR) in additions history so Inspect Additions/History windows show the same combined preview.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/UI/Features/Ocr/OcrViewModel.cs | Keeps richer match metadata for inspect and stores preview bitmaps for history. |
| src/UI/Features/Ocr/NOcr/NOcrInspectViewModel.cs | Uses display bitmap/rect/top-margin so grouped matches preview/highlight correctly. |
| src/UI/Features/Ocr/NOcr/NOcrCharacterHistoryViewModel.cs | Uses stored preview bitmap when showing history items. |
| src/UI/Features/Ocr/NOcr/NOcrAddHistoryManager.cs | Renames stored bitmap parameter to preview bitmap for clarity/consistency. |
| src/UI/Features/Ocr/NOcr/NOcrAddHistoryItem.cs | Stores a cloned PreviewBitmap instead of Bitmap. |
| src/UI/Features/Ocr/BinaryOcr/BinaryOcrInspectViewModel.cs | Tracks display bitmap/bounds/top-margin and performs exact-match checks for expanded groups. |
| src/UI/Features/Ocr/BinaryOcr/BinaryOcrCharacterHistoryViewModel.cs | Uses stored preview bitmap + preview top margin when displaying expanded-history items. |
| src/UI/Features/Ocr/BinaryOcr/BinaryOcrAddHistoryManager.cs | Extends history add API to include preview top margin. |
| src/UI/Features/Ocr/BinaryOcr/BinaryOcrAddHistoryItem.cs | Stores cloned PreviewBitmap + PreviewTopMargin. |
| patches-github/0001-Fix-nOCR-two-byte-character-load-save-handling.patch | Adds a git patch file (currently appears unrelated/out-of-date vs current code). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| From cf2d41ec49863362fc0e876f1cf20a26a3b1a20e Mon Sep 17 00:00:00 2001 | ||
| From: "Hellgringer.Online" <Hellbringer.Online@gmail.com> | ||
| Date: Mon, 6 Apr 2026 21:43:29 +0400 | ||
| Subject: [PATCH] Fix nOCR two-byte character load/save handling | ||
|
|
||
| --- | ||
| src/UI/Logic/Ocr/NOcrChar.cs | 5 +++-- | ||
| 1 file changed, 3 insertions(+), 2 deletions(-) | ||
|
|
||
| diff --git a/src/UI/Logic/Ocr/NOcrChar.cs b/src/UI/Logic/Ocr/NOcrChar.cs | ||
| index d53a2a070..30fb539bb 100644 | ||
| --- a/src/UI/Logic/Ocr/NOcrChar.cs |
There was a problem hiding this comment.
This patch file appears unrelated to the PR’s stated goal (inspect preview rendering) and the changes it describes (e.g., incrementing position in the long-format reader and fixing IsAllByteValues to check LinesBackground) are already present in src/UI/Logic/Ocr/NOcrChar.cs. Keeping an unapplied/out-of-date patch here is likely to confuse future maintenance; consider removing it or updating the patch series mechanism/documentation if this folder is meant to be consumed by tooling.
Summary
This fixes OCR inspect windows so grouped matches (ExpandCount > 1) render the full combined image instead of only the first split segment.
Problem
When Inspect image matches opened a grouped match such as do, the right-hand Current image preview and the red rectangle on the sentence preview were based on the first ImageSplitterItem2 only.
This happened for two different reasons:
OCR: OcrViewModel rebuilt inspect matches as reduced NOcrChar objects, which dropped ExpandCount, dimensions, MarginTop, and draw-line metadata before the inspect dialog opened.
The same issue also leaked into inspect additions/history flows, where preview items for expanded matches were stored as the first segment instead of the combined preview bitmap.
Changes
OCR inspect preview top-margin handling aligned with grouped previews.
Result
After this change, grouped OCR matches like do are displayed consistently across:
Single-character matches keep the old behavior.
Verification
Screenshot