Skip to content

fix(sender): correct emoji character counting#313

Open
SonyLeo wants to merge 1 commit intoopentiny:developfrom
SonyLeo:fix/sender-emoji-counter
Open

fix(sender): correct emoji character counting#313
SonyLeo wants to merge 1 commit intoopentiny:developfrom
SonyLeo:fix/sender-emoji-counter

Conversation

@SonyLeo
Copy link
Collaborator

@SonyLeo SonyLeo commented Mar 17, 2026

背景

修复字符计数在 emoji、复合字符场景下不准确的问题。

问题说明

Emoji / 复合字符计数不准确

Sender 的字数统计此前基于普通字符串长度计算。对于 emoji、国旗、肤色修饰符、ZWJ 组合字符等场景,一个用户可见字符可能会被统计成多个 code units,导致:

  • 字数统计偏大
  • 限制字数时行为不符合用户预期
  • Sender 字数提示与真实输入感知不一致

变更内容

Sender 字符计数改为 grapheme 级统计

  • 引入 grapheme-aware 计数逻辑
  • 优先使用 Intl.Segmenter
  • 对不支持 Intl.Segmenter 的环境使用 unicode-segmenter 兜底
  • 使 emoji、复合字符等按“用户可见字符”统计

影响范围

  • 影响 Sender 的字符计数和字数限制相关逻辑

验证方式

已重点验证以下场景:

  • emoji、复合字符、ZWJ 组合字符计数符合预期
001 002 003 004

Summary by CodeRabbit

  • New Features

    • Added bubble and floating menu options to the text editor.
  • Improvements

    • Upgraded text editor library to the latest version with enhanced stability and features.
    • Improved text character counting accuracy for special characters and multi-byte text.
  • Chores

    • Updated editor dependencies to latest versions.
    • Added TypeScript support for modern internationalization features.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Walkthrough

The PR upgrades TipTap dependencies from v3.11.0 to v3.17.1, adds bubble menu and floating menu extensions, introduces grapheme cluster counting via a new utility with Intl.Segmenter support, and updates TypeScript configuration accordingly.

Changes

Cohort / File(s) Summary
TipTap Dependency Upgrade
packages/components/package.json
Upgrades all TipTap packages from v3.11.0 to v3.17.1, adds new extensions (bubble-menu, floating-menu, extensions package), and introduces unicode-segmenter dependency for grapheme counting.
Grapheme Counting Implementation
packages/components/src/sender/utils/countGraphemes.ts
New utility function that counts grapheme clusters using Intl.Segmenter with fallback to unicode-segmenter for environment compatibility.
Editor Configuration Updates
packages/components/src/sender/composables/useEditor.ts, packages/components/src/sender/composables/useSenderCore.ts
Integrates grapheme-aware text measurement into editor configuration and replaces character counting logic from simple text length to grapheme-based counting.
TypeScript Configuration
packages/components/tsconfig.json
Adds "ES2022.Intl" library support to enable Intl.Segmenter type definitions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Through letters and grapheme clusters we hop,
TipTap's v3.17 makes text measurement stop,
With bubbles and menus that float through the air,
Unicode segmenting shows we truly care!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(sender): correct emoji character counting' accurately reflects the primary objective of the PR, which is to correct emoji and grapheme character counting in the Sender component.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SonyLeo SonyLeo linked an issue Mar 17, 2026 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

✅ Preview build completed successfully!

Click the image above to preview.
Preview will be automatically removed when this PR is closed.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

@SonyLeo SonyLeo changed the title feat(sender): implement grapheme-aware character counting fix(sender): correct emoji character counting and pin tiptap dependencies Mar 17, 2026
@SonyLeo SonyLeo marked this pull request as ready for review March 17, 2026 03:25
@SonyLeo SonyLeo force-pushed the fix/sender-emoji-counter branch from bdfe53c to 130d2e8 Compare March 17, 2026 13:29
@SonyLeo SonyLeo changed the title fix(sender): correct emoji character counting and pin tiptap dependencies fix(sender): correct emoji character counting Mar 17, 2026
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.

【bug】emoji 字数统计

1 participant