maxLengthSingleLineRendering truncation can split grapheme clusters (emoji/ZWJ)

Open Beginner friendly
#104 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
dart, flutter
Domain
frontend

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

  1. Enable wordWrap: true
  2. Set maxLengthSingleLineRendering to a small number
  3. Type/paste an emoji sequence around the boundary, e.g.:
    • Surrogate pair: 😀
    • ZWJ sequence: 👨‍👩‍👧‍👦 or 👩‍❤️‍💋‍👩
  4. 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 plainText substring.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reqable/re-editor

All issues in reqable/re-editor

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.