Skip to content

fix: treat marks with unset inclusive as inclusive when configuring text style - #81

Open
frioux wants to merge 1 commit into
loro-dev:mainfrom
frioux:fix-default-inclusive-marks
Open

fix: treat marks with unset inclusive as inclusive when configuring text style#81
frioux wants to merge 1 commit into
loro-dev:mainfrom
frioux:fix-default-inclusive-marks

Conversation

@frioux

@frioux frioux commented Jul 31, 2026

Copy link
Copy Markdown

Summary

configLoroTextStyle maps a mark's expand behavior with markType.spec.inclusive ? "after" : "none". But ProseMirror's MarkSpec.inclusive defaults to true when unset, and mainstream marks (Tiptap's bold, italic, strike, code, ...) never set it. The truthiness check maps "unset" to "none", so for every default-inclusive mark ProseMirror extends the mark over text typed at its end while Loro does not — the two sides of the binding permanently disagree about mark boundaries.

The practical cost: every character typed while extending a bold/italic/code run lands at the run's end, so on every such keystroke the PM document and the Loro doc diverge and the binding has to emit extra style ops to repair the difference. Those redundant mark ops leave style anchors behind in the container state forever, so heavily edited styled paragraphs get permanently slower to read.

Fix

{ expand: markType.spec.inclusive !== false ? "after" : "none" }

Only an explicit inclusive: false now maps to "none", matching ProseMirror's documented semantics.

Validation

Added tests/text-style.test.ts covering the three cases (unset, explicitly true, explicitly false); the unset case fails without this change. pnpm test, pnpm lint, and pnpm check-format all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KQw7nfh6KaUhQy6ZQUZwMm

…ext style

ProseMirror's MarkSpec.inclusive defaults to true when unset, and
mainstream marks (bold, italic, strike, code, ...) never set it. The
truthiness check mapped "unset" to expand "none", so ProseMirror
extended these marks over text typed at their end while Loro did not,
making the two sides disagree about mark boundaries on every keystroke
of styled typing.
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.

1 participant