SIGN IN SIGN UP

Fixes #330 surrogate pair handling in simpleSearch context slicing (#331)

* Add failing tests for surrogate-splitting search context

simpleSearch reports matches as UTF-16 code-unit offsets and slices the
context window in code units, so a contextLength boundary can land between
the two halves of a surrogate pair (e.g. the emoji 🔌 = U+D83D U+DD0C),
returning an unpaired surrogate in the context string. See issue #330.

Co-Authored-By: DeepSeek V4 <noreply@deepseek.com>

* Keep simpleSearch context on code-point boundaries

Obsidian's simple search reports match offsets as UTF-16 code units, and the
context window was sliced in code units too, so a contextLength boundary could
fall between the two halves of a surrogate pair and return an unpaired
surrogate (e.g. \udd0c) in the match context. Adjust the slice bounds so they
never bisect a surrogate pair, clamping the start and end back onto the
complete character. Fixes #330.

Co-Authored-By: DeepSeek V4 <noreply@deepseek.com>

* Rename the surrogate-boundary helper and document it as JSDoc

adjustContextBounds said nothing about how it adjusts or why. The helper only
ever widens a code-unit range, and the property it guarantees is that both
ends land on code-point boundaries, so it is now widenToCodePointBoundaries,
with a generic `text` parameter since nothing in it is search-specific.

The leading comment becomes a JSDoc that records the verified contract
(grow-only, at most one code unit per side, no-op on in-range and edge bounds,
does not repair pre-existing lone surrogates) and explains why
String.prototype.toWellFormed() is not a substitute: it runs on the sliced
string after the other half of the pair is gone, and it replaces lone
surrogates with U+FFFD rather than restoring the character.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Zopper <jan@tulak.me>
Co-authored-by: DeepSeek V4 <noreply@deepseek.com>
Co-authored-by: Adam Coddington <me@adamcoddington.net>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
J
Jan Ťulák committed
ce07d55173288cadeb6cdaf7f306cbccd9f36ffd
Parent: 85c12e6
Committed by GitHub <noreply@github.com> on 8/24/2026, 10:41:32 PM