Skip to content

fix: surrogate pair corruption in structural char protection fallback backspace/delete#749

Merged
xiaolai merged 1 commit intomainfrom
fix/audit-695
Apr 8, 2026
Merged

fix: surrogate pair corruption in structural char protection fallback backspace/delete#749
xiaolai merged 1 commit intomainfrom
fix/audit-695

Conversation

@xiaolai
Copy link
Copy Markdown
Owner

@xiaolai xiaolai commented Apr 8, 2026

Closes #695

Summary

  • Use findClusterBreak from @codemirror/state instead of naive head ± 1 in the non-structural cursor fallback path of smartBackspace and smartDelete
  • The old code split surrogate pairs (emoji, astral-plane CJK) when a multi-cursor session had at least one cursor at a structural position (table pipe, list marker, etc.)
  • Added regression tests with emoji surrogate pairs for both backspace and delete paths

Test plan

  • New tests: surrogate pair backspace + delete with multi-cursor structural protection
  • All 663 test files pass (pnpm check:all)
  • Build succeeds

🤖 Generated with Claude Code

… backspace/delete (Closes #695)

Use findClusterBreak instead of naive head±1 to respect surrogate pairs
and grapheme clusters in the non-structural cursor fallback path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xiaolai xiaolai added the audit Codebase audit finding label Apr 8, 2026
@xiaolai
Copy link
Copy Markdown
Owner Author

xiaolai commented Apr 8, 2026

VERIFIED — The fix replaces the naive head - 1 / head + 1 fallbacks with CodeMirror's findClusterBreak(), which correctly handles surrogate pairs and grapheme clusters, and includes regression tests for both backspace and delete with emoji at non-structural cursors.

@xiaolai xiaolai enabled auto-merge (squash) April 8, 2026 15:06
@xiaolai xiaolai merged commit 434c2d8 into main Apr 8, 2026
8 checks passed
@xiaolai xiaolai deleted the fix/audit-695 branch April 8, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit Codebase audit finding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit] codemirror: surrogate pair corruption in structural char protection fallback backspace/delete

1 participant