Skip to content

mixin_markdown_widget: select whole Chinese words on double click - #550

Merged
boyan01 merged 1 commit into
mixin_markdown_widget/selection-leaf-refactorfrom
mixin_markdown_widget/cjk-word-segmenter
Oct 21, 2026
Merged

boyan01 merged 1 commit into
mixin_markdown_widget/selection-leaf-refactorfrom
mixin_markdown_widget/cjk-word-segmenter

Conversation

@boyan01

@boyan01 boyan01 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #544. Double clicking Chinese text selected one character because Flutter's bundled ICU has no CJK dictionary. Word selection now asks word_segmenter (#548) first.

 markdownWordRangeAt(text, offset, upstream)
   run = characters between whitespace / separators (incl. CJK punctuation)
   if run is ASCII → return run
-  TextPainter.getWordBoundary(run, index)        # 我们 → 我
+  wordBoundaries(run)?.segment containing index   # CFStringTokenizer / system ICU / Intl.Segmenter
+  ?? TextPainter.getWordBoundary(run, index)      # no platform segmenter
  • New dependency: word_segmenter: ^0.1.0 (already on pub.dev; resolves to the workspace package here).
  • ASCII runs and separator handling are unchanged.

Evidence

Before: the strengthened markdown_word_selection_test.dart against the old lib/:

Chinese text breaks at dictionary words           Expected: '我们'  Actual: '我'
double click selects a word in a Chinese paragraph Expected: '效果'  Actual: '效'

After: 5/5. 我们使用Flutter开发桌面应用 selects 我们 / 使用 / Flutter / 开发 / 桌面 / 应用 at every offset and from the right half of each word's last character; double click on 效 selects 效果, on 桌 selects 桌面.

Platform flutter test (package)
macOS 27 267 passed
Windows (remote, system icu.dll) 267 passed
Ubuntu 22.04 (remote WSL, system libicuuc) 267 passed

flutter analyze: no issues. Not checked by hand in the GUI yet.

Merge Danger

Door: two-way

Blast Radius: selection

Only double-click word selection in non-ASCII runs changes. Segments come from platform dictionaries, so the exact word can differ by platform (e.g. macOS splits 很好 into 很 / 好). Platforms without a segmenter (Android < 31, very old Windows) keep the previous per-character behavior. Releasing the next mixin_markdown_widget adds word_segmenter to consumers' dependency trees.

Flutter's bundled ICU has no CJK dictionary, so double clicking Chinese text
selected a single character. Word selection now asks `word_segmenter`, which
uses the platform's segmenter (CFStringTokenizer, system ICU, or
Intl.Segmenter) and falls back to `TextPainter.getWordBoundary` when the
platform has none. `我们使用Flutter开发桌面应用` now selects `开发` instead of
`开`.

Adds a dependency on `word_segmenter: ^0.1.0`.
@boyan01
boyan01 added this pull request to stack #545 October 20, 2026 13:33
@boyan01
boyan01 merged commit e19cacc into main Oct 21, 2026
7 checks passed
@boyan01
boyan01 deleted the mixin_markdown_widget/cjk-word-segmenter branch October 21, 2026 01:49
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