Skip to content

#1043 Cut emoji text alike on both platforms, close markers a cut leaves open - #1072

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/1043-cut-emoji-and-markers
Nov 16, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/1043-cut-emoji-and-markers

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1049 for #1043. It fixes two defects a device check of the cut user messages found.

1. The same emoji-heavy message was cut in different places. iOS counted line cost in grapheme clusters and Android in UTF-16 units, so the same message showed 25 lines and "1,031 of 1,493 characters shown" on iOS but 17 lines and "695 of 1,493" on Android.

  • Both platforms now count UTF-16 units. A Kotlin String and Swift's String.utf16 both read UTF-16 one unit at a time without decoding, so the pass stays cheap and still stops early. Counting grapheme clusters would mean segmenting every character read. The choice is recorded in the doc comment next to the constants.
  • iOS MessageTextLimit now mirrors the Android algorithm. It works on the UTF-16 units read so far and reads more only when it needs them, so a multi-megabyte message still reads about 1,230 units.
  • A cut never ends inside a grapheme cluster: not inside a surrogate pair, a ZWJ sequence, a flag, a skin tone or variation selector, or a letter with combining marks. Only the cut line is segmented, from its start to one code point past the cut, using each platform's own rules: Swift Character on iOS and regex \X on Android. This replaces Android's surrogate-pair check.
  • iOS row counts now come straight from the cut, and no longer from text.prefix(n).utf16.count.

2. A marker left open by a cut mid-line showed literally, for example a ** before bold words. The cut now records whether it ended mid-line (endsMidLine). If it did, MessageTextCut.markdownSource passes the shown part through OpenCodeMarkdownParser.closeMarkersLeftOpen, a new function in the shared markdown-core parser, before adding the "…". Both apps call this one implementation.

  • It follows the parser's own inline scan over the cut line. Where that scan finds no closer for a marker, it adds the closer before the "…", inner markers first. This covers bold, italic, inline code, and an image whose alt text or destination was cut; only the alt text renders, and the image is never loaded. If adding the closer would make the parser close the outer marker early, it drops the inner opener instead.
  • A link whose text or destination was cut shows its text as plain text, because its destination is missing or incomplete.
  • Left unchanged:
    • a cut line inside a code fence, on a fence line, or in a table row;
    • markers inside inline code;
    • an opener after a backslash (\*), after a letter or digit (snake_case), or followed by a space;
    • ~~, because the parser has no strikethrough, so the whole message shows the tildes too.
  • Only the text given to markdown detection and parsing changes. The plain shown text, Copy message, Select text and the Full message sheet are unchanged.

Checks

  • Android: ./gradlew :app:assembleDebug succeeds. :app:testDebugUnitTest for dev.opencode.mobile.domain.message.* and dev.opencode.mobile.ui.sessionchat.*: 0 failures. :markdown-core:testDebugUnitTest: passes.
  • iOS: xcodebuild build and build-for-testing for generic/platform=iOS Simulator: both succeed. The iOS tests were not run locally (no simulator was available); CI runs them.
  • The same test vectors on both platforms (MessageTextLimitTest(s), MessageTextCutMarkdownTest(s), and one row-count case in the presentation tests). Each asserts the shown text and both counts:
    • emoji-only lines and an emoji-only long line;
    • mixed words and emoji;
    • a ZWJ family, flags (split pair and pair boundary), a skin tone, VS16 and a combining mark at the cut;
    • CJK on one line and over several lines;
    • every marker type, nested markers, a marker that closes before the cut, an escaped marker, an opener inside inline code, a cut inside a fence, and list and heading lines. These assert both the repaired source and the parsed blocks.
  • The existing ASCII vectors keep their results.
  • No screenshots: no simulator or emulator was available for this change.

Risks / Follow-ups

  • On-device rendering of the repaired markers and the new emoji cut was not checked on either platform.
  • Swift and the regex engine can disagree on rarer grapheme sequences (for example Unicode 15.1 Indic conjuncts on JDK 17), so the cut may land one cluster apart there. The shared vectors cover the common sequences.
  • The marker repair works only on the cut line. An opener on an earlier line of the same paragraph that closes after the cut is not repaired. An opener the full message never closes is still closed.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…ves open

Count a cut user message in UTF-16 units on iOS as on Android, so the same
text is cut at the same place and shows the same counts. The cut never
ends inside a grapheme cluster: the cut line up to the cut is segmented
with each platform's own rules (Swift Character, regex \X).

Before the shown part of a line cut part way reaches the markdown parser,
the shared parser closes the bold, italic and inline code the cut left open
and drops the opener of a cut link, so the bubble renders as the whole
message does up to the cut. The plain shown text and the full text are
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko marked this pull request as ready for review November 16, 2026 08:34

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: no finding that 2+ of 3 passes agreed on.

4 finding(s) from a single pass, not posted
  • shared/markdown-core/src/commonMain/kotlin/dev/opencode/mobile/markdown/OpenCodeMarkdown.kt:398 high: Opener on earlier paragraph line never closed (muse-spark-1.3-contributor)
  • shared/markdown-core/src/commonMain/kotlin/dev/opencode/mobile/markdown/OpenCodeMarkdown.kt:504 medium: Cut bare URL keeps ellipsis inside link destination (muse-spark-1.3-contributor)
  • shared/markdown-core/src/commonMain/kotlin/dev/opencode/mobile/markdown/OpenCodeMarkdown.kt:547 medium: Intra-word opener treated literal while parser pairs it (muse-spark-1.3-contributor)
  • shared/markdown-core/src/commonMain/kotlin/dev/opencode/mobile/markdown/OpenCodeMarkdown.kt:499 low: A literal '[' cut mid-line is dropped from the rendered bubble (deepseek-v4.1-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.091 · 2 pass(es) stopped early

@ivanfenenko
ivanfenenko added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 6fe55c0 Nov 16, 2026
@ivanfenenko
ivanfenenko deleted the fix/1043-cut-emoji-and-markers branch November 16, 2026 09:48
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