mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
* fix: correct find-and-replace highlight positions for CJK/Hangul text The in-document find feature searched over `deburr(text) + text` and assumed the deburred prefix had the same length as the original, mapping match indices with `m.index - text.length`. `deburr` normalizes to NFD form, which decomposes precomposed CJK/Hangul syllables (e.g. "강" is one UTF-16 code unit but decomposes into three jamo), so the deburred prefix is longer than the original. This broke the boundary assumption, producing misaligned highlights, undercounted matches, and out-of-bounds positions (the "array index out of bounds" console error from expandCollapsedCodeBlockForCurrentMatch). Replace the length-based offset math with an explicit index map built by `deburrWithMap`, which records the original index of every emitted code unit. The text is searched both deburred (diacritic-insensitive) and verbatim, with each match translated back to its true position via the map. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKAYuiMFqpBNbCPirhe8yk * refactor: extract deburrWithMap into its own module with unit tests Move the diacritics-stripping/index-map helper out of the extension into a dedicated module so it can be unit-tested in isolation without pulling in the editor's React/ProseMirror component tree. Add tests covering ASCII, diacritics, Hangul (NFD-expanded) text, ASCII matches surrounded by CJK, and surrogate pairs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKAYuiMFqpBNbCPirhe8yk * perf: add fast path to deburrWithMap to avoid per-character work Only build the per-character index map when deburring actually changes the string length (NFD-decomposed CJK/Hangul, expanded ligatures). For ASCII and ordinary accented Latin text – where length is preserved and indices line up 1:1 – return an identity mapping with no per-character table, and skip the redundant second search pass over deburred text when it equals the original. Within the slow path, skip normalization of ASCII characters. This keeps the common case as cheap as a single deburr() call (~0.4ms/keystroke on a 100k-char document) and roughly halves the mixed-CJK cost. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKAYuiMFqpBNbCPirhe8yk * test: cover interleaved ASCII and Hangul in deburrWithMap Verify the index map stays consistent when ASCII characters (which take the fast skip branch) are interleaved with Hangul characters (which decompose under NFD), so every ASCII match still resolves to its exact original code unit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKAYuiMFqpBNbCPirhe8yk * fix: skip zero-length deburred matches and reduce slow-path allocations Address review feedback on the CJK find-and-replace fix: - A regex match against the deburred text can cover only part of a decomposed sequence (e.g. a single jamo of a Hangul syllable), which maps back to a zero-length range in the original text. Recording such a range made replace behave like an insert (from === to); skip matches where to <= from. - Build the deburred string in the slow path by joining an array of parts once instead of repeated string concatenation in the loop, keeping it linear with less allocation churn. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKAYuiMFqpBNbCPirhe8yk --------- Co-authored-by: Claude <noreply@anthropic.com>