Repository navigation
Description
Description
将其他地方(比如AI对话的回答中)复制的emoji表情复制到使用MarkText打开的md文档中再删除后会报错:意外的渲染进程错误
Steps to Reproduce
- 将emoji表情复制到使用MarkText打开的md文档中
- 在默认的编辑模式下删除emoji表情
- MarkText报错意外的渲染进程错误
Expected Behavior
删除emoji后正常渲染无报错
Actual Behavior
报错意外的渲染进程错误
Screenshots / Logs
意外的渲染进程错误
Error: Invalid offset - splits unicode bytes
at unicount.strPosToUni (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:99249:13)
at exports2.dlen (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:99332:70)
at checkOp (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:99281:26)
at Object.apply (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:99583:11)
at drop2 (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:146616:57)
at drop2 (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:146611:27)
at Object.apply2 [as apply] (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:146621:9)
at JSONState._apply (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:147289:44)
at JSONState._flushOperationCache (file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:147442:10)
at file:///C:/Users/x/AppData/Local/Programs/marktext/resources/app.asar/out/renderer/assets/index-D8Yzs57g.js:147422:12
Operating System
Windows
MarkText Version
v0.20.0-rc.1
OS Version
Windows 11
Reproducibility
- I can reliably reproduce this issue
Activity
Renakoni commentedon Jul 15, 2026
Does this issue happen with all emojis? Could you give me some specific examples? That way, I can add concrete tests for them.
ACodeCopyer commentedon Jul 15, 2026
I am not sure if this issue happen with all emojis, but when I input 🙂(微笑)😀(大笑) , it will happen.
Renakoni commentedon Jul 15, 2026
Thanks for the example! 🙏 That 🙂(微笑)😀(大笑) case was really helpful — I've used it directly in the tests.
It turned out to be more interesting than it looks, so a quick explanation:
Emoji like 🙂 and 😀 aren't single characters under the hood — each is stored as two UTF‑16 "code units" (a surrogate pair). The crash happens when the caret ends up between those two halves and you press Backspace/Delete: the editor removes only one half and leaves a "lone surrogate," which the underlying text engine (ot-text-unicode) can't encode — that's the Invalid offset - splits unicode bytes error you saw.
Two things worth clarifying:
The fix (#4931) makes deletion surrogate‑aware: it snaps the caret to a whole‑character boundary before deleting, then removes the emoji as a single code point. Unit + end‑to‑end tests are included, using your exact 🙂(微笑)😀(大笑) example.
这个问题比想象中有意思 简单说:像 🙂 😀 这类 emoji 在底层其实是两个 UTF‑16 编码单元拼起来的(代理对)。当光标正好卡在这两半中间时按删除键,编辑器只删掉了其中一半,留下“半个字符”,底层文本引擎没法处理,就崩了(也就是你看到的 Invalid offset - splits unicode bytes)。
ACodeCopyer commentedon Jul 15, 2026
Oh, that explains everything. Thanks for fix it!🙏
fix: cherry-pick upstream crash and large-document fixes
fix: cherry-pick upstream crash and large-document fixes
fix(muya): delete whole grapheme clusters, not code units or code poi…
fix(muya): delete whole grapheme clusters, not code units or code poi…
fix: marktext#4926 prevent emoji deletion from splitting surrogate pa…
fix(muya): delete emoji whole in code blocks and drop the caret-insid…
fix(muya): regex search freezes on zero-width patterns and splits emo…
fix: Backspace removes what upstream MarkText removes over combining …
fix: Backspace removes what upstream MarkText removes over combining …