maxLengthSingleLineRendering truncation can split grapheme clusters (emoji/ZWJ)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start in lib/src/_code_paragraph.dart at the maxLengthSingleLineRendering path and its trucate(TextSpan, int) helper. Reproduce with wordWrap enabled, a small limit, and the listed emoji sequences, then inspect how both TextSpan.text and plainText are truncated. Done means truncation stops at grapheme-cluster boundaries consistently in both paths without broken rendering.
Written by the indexing model from the issue text.
Description
Problem
When using CodeEditor.maxLengthSingleLineRendering, Re-Editor truncates a long single line by doing substring(0, N) on TextSpan.text / plainText. This counts UTF-16 code units and may cut in the middle of a grapheme cluster (surrogate pairs, ZWJ sequences, variation selectors).
This can lead to broken rendering (e.g. replacement character "�"), and potentially inconsistent caret/selection hit-testing near the truncation boundary.
Where
lib/src/_code_paragraph.dart:
// current implementation
if (renderingLength != null && plainText.length > renderingLength) {
impl = _build(trucate(span, renderingLength), plainText.substring(0, renderingLength), true);
}
TextSpan trucate(TextSpan span, int maxLength) {
// ...
if (text.length > remainingLength) {
text = text.substring(0, remainingLength);
}
// ...
}
Repro
- Enable
wordWrap: true - Set
maxLengthSingleLineRenderingto a small number - Type/paste an emoji sequence around the boundary, e.g.:
- Surrogate pair:
😀 - ZWJ sequence:
👨👩👧👦or👩❤️💋👩
- Surrogate pair:
- If truncation cuts inside the sequence, rendering becomes broken.
Suggestion
Make truncation grapheme-safe:
- Use
package:characters(grapheme cluster iterator) to compute a safe prefix length <= maxLength (code units) and truncate at cluster boundaries. - Apply the same safe length to both the span truncation and the
plainTextsubstring.
This keeps the performance guard while avoiding invalid Unicode sequences.
Thanks!
- Dominant language
- Dart
- Stars
- 761
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reqable/re-editor
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
-
enhancement
-
bug
-
大文件向上滚动卡顿 Openbug
All issues in reqable/re-editor
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
code quality good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Suwayomi/Suwayomi-Tsumiru#479 ·
-
Build Failure: agora_rtc_engine compiled against android-31 while dependencies require android-34+ Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
conceptadev/noir#95 ·