A search highlight in the wrong place can come from incompatible offset units. Bytes, code points, UTF-16 units and positions in displayed text nodes should not be used interchangeably.
Match offsets to the same text version
A personal sms message inbox may search a representation that differs from the final display. Stripped markup, line changes, normalisation or translation can make an earlier position unsuitable for the page. Identify the text version actually matched before adjusting the index.
MDN's JavaScript string-length documentation explains UTF-16 units. Check the actual definition used by the matching language or library and the renderer. Counting visible symbols by eye does not establish which unit the result expresses.

Make the display mapping deliberate
Relate the supported source position to the rendered text, using a defined mapping where a transformation requires it. Do not alter an original code or business identifier merely to align a highlight. A display aid should not become the input used later for authentication.
| Boundary | Relationship to establish |
|---|---|
| Source | The text version searched |
| Unit | Bytes, code points or string units |
| Transformation | Changes to characters or text nodes |
| Output | Safe insertion of the visual emphasis |
Message content still needs safe data presentation. Do not concatenate an arbitrary match into executable HTML to repair a location defect. Correct offsets and safe output handling are separate properties that should both remain in the design.
Use boundary fixtures, not only ordinary letters
Cover Chinese text, emoji, combining sequences, multiple lines and several matches with harmless samples. Include an updated message so a late search result cannot place an old offset onto a newer body. A request relationship and text-version check can make that transition explainable.
Inspect matches at the start and end of the supported text as well. A boundary calculation that works in the middle can still drop a final unit or highlight outside the intended node. Use the renderer's actual text rather than a separately reconstructed approximation.
If matching uses a transformed search representation, keep a supported relationship to the original text rather than returning its offsets as though nothing changed. Some transformations can change length or combine sequences. The renderer needs either correctly mapped locations or another safe way to identify the intended source span. Do not search-and-replace the original to force the positions to agree. A controlled fixture can record the source, transformed search text and expected visible span together. That gives the reviewer concrete evidence about the mapping and avoids confusing a correct search hit with a correct highlight. Keep the same version relationship when several asynchronous results arrive in a different order.

Keep investigation material limited
A small sample, match position and unit definition can reproduce many failures without exporting an entire private inbox. Genuine message contents should not be sent to public debugging or analytics tools when they are unnecessary to the offset question.
Compare the intended match, rendered highlight and preserved source after the repair. Highlighting remains a reading aid: it does not establish message identity, complete historical coverage or a user's business completion. The useful result is an accurate visible relationship to the original text, not another interpretation of the message's authority.
