Skip to content

fix: 🐛 修复textarea统计多码元字符长度错误的问题 - #940

Merged
Moonofweisheng merged 1 commit into
Moonofweisheng:masterfrom
RJQingHuan:fix-tearea-lenth
Mar 14, 2025
Merged

fix: 🐛 修复textarea统计多码元字符长度错误的问题#940
Moonofweisheng merged 1 commit into
Moonofweisheng:masterfrom
RJQingHuan:fix-tearea-lenth

Conversation

@RJQingHuan

@RJQingHuan RJQingHuan commented Mar 13, 2025

Copy link
Copy Markdown
Collaborator

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

close #933

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • Bug Fixes
    • 改进了文本区域字符计数功能,确保在输入多字节字符(如中文、表情符号等)时能够准确统计字符数量,提升用户体验。

@vercel

vercel Bot commented Mar 13, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 13, 2025 2:57am

@coderabbitai

coderabbitai Bot commented Mar 13, 2025

Copy link
Copy Markdown

Walkthrough

该 PR 修改了 wd-textarea 组件中 currentLength 的计算方式。从原先直接获取字符串长度改为使用 Array.from 方法对格式化后的值进行处理,以正确统计多字节字符的长度。同时代码中添加了中文注释并附上了问题链接,公共实体的声明未发生变化。

Changes

文件 变更摘要
src/uni_modules/.../wd-textarea/wd-textarea.vue 修改 currentLength 计算逻辑,使用 Array.from 处理多字节字符,添加中文注释和问题链接。

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

我是一只跳跃的小兔子,
在代码林间自由穿行,
多字节字符不再迷路,
精准计算写下新章,
代码花园春意盎然,
让我们一起欢笑前行! 🐇🌸

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7478939 and 9e1180b.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue (1 hunks)
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue (1)

173-179: 很好的修复,正确处理了多字节字符的长度计算!

这个修改使用 Array.from() 方法来正确计算字符串长度,解决了 JavaScript 中字符串 .length 属性只计算 UTF-16 编码单元数而非用户感知字符数的问题。对于表情符号、复杂汉字等多字节字符,这种方法能确保每个字符被正确计为一个单位,从而修复了文本长度限制的统计错误。

代码添加的注释清晰地解释了修改原因并提供了问题链接,非常有助于后续维护。


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify

netlify Bot commented Mar 13, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9e1180b
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67d2493cb1168300080d36bf
😎 Deploy Preview https://deploy-preview-940--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Moonofweisheng
Moonofweisheng merged commit f9d8523 into Moonofweisheng:master Mar 14, 2025
@RJQingHuan
RJQingHuan deleted the fix-tearea-lenth branch March 17, 2025 01:03
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 上报] wot-textarea字符统计数量不对

2 participants