Skip to content

fix: anchor text cursors at non-BMP UTF-16 boundaries - #1103

Open
hngpt52 wants to merge 1 commit into
loro-dev:mainfrom
hngpt52:codex/fix-loro-1101-cursor-unicode
Open

hngpt52 wants to merge 1 commit into
loro-dev:mainfrom
hngpt52:codex/fix-loro-1101-cursor-unicode

Conversation

@hngpt52

@hngpt52 hngpt52 commented Sep 13, 2026

Copy link
Copy Markdown

Fixes #1101.

LoroText.getCursor() can return undefined at the start of an emoji when that character occupies its own text atom. It can also accept a position inside a surrogate pair and anchor it at the preceding boundary.

The stable-position lookup now verifies that the queried cursor maps back to the requested index and, for WASM event indices, selects the full UTF-16 width of the character. Native Unicode indexing, cursor sides, and end-of-document behavior are preserved. No public signatures or serialized formats change.

Regression coverage includes mixed non-BMP text, combining sequences, mid-surrogate positions, separate-peer atoms, cursor resolution after remote edits, and native Rust controls. A patch changeset is included; the code comment explains why the index round trip is necessary.

Validation

  • Demonstrated the WASM regression failing on the base build and passing with the fix.
  • Release WASM build and package tests passed: 375 Vitest tests, TypeScript, CommonJS smoke, 4 Deno tests, and 4 Bun tests.
  • Native cursor contract selection: 9 passed; internal rich-text selection: 60 passed; cargo check -p loro-internal passed.
  • Independent review reran all 27 tests in the changed WASM rich-text file and the 9 native cursor tests, plus additional probes at formatting boundaries.
  • Changed Rust files pass rustfmt; git diff --check passes.

Repository-wide formatting and Clippy are not green on the unmodified base with the local Rust 1.98 toolchain (unrelated formatting differences and existing generic-btree diagnostics). No unrelated formatting or dependency changes are included. WASM package tests used a temporary empty PostCSS configuration to avoid an unrelated configuration in the parent directory; that workaround is not part of this patch.

Validate UTF-16 character boundaries and select the complete scalar when creating stable text cursors. Cover cross-peer atoms, remote edits, and native indexing.

Fixes loro-dev#1101

Agent: codex-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getCursor returns undefined at the start of a non-BMP character

1 participant