Typing or autocorrecting inside a mention strips it to plain text

未关闭
#855 8 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ios, objective-c, react-native
领域
frontend, mobile

调研方向

Start in the iOS implementation of shouldChangeTextInRange:replacementText: and read MentionStyle.remove:withDirtyRange: plus handleExistingMentions; the issue identifies these paths and getMentionParamsAt: as relevant. Check how edits inside and at the edges of a mention affect its attributes and emitted HTML. Done means typing, autocorrecting, or backspacing cannot leave visible plain text with the mention id silently lost; verify both whole mention deletion and edits beside it.

由索引模型根据 Issue 内容生成。

描述

Description

On iOS, any edit that lands inside a mention silently strips it to plain text. The name stays on screen, the <mention> tag disappears from the emitted HTML, and the id with it — so a reader still sees what looks like a mention, while the application has lost the person it pointed to. In a messaging app that means the mentioned user is never notified, and nothing on screen says so.

This is the same model as #691, which was reported and fixed for Android. That issue states the intended behaviour, and I agree with it:

it should either stay intact or be deleted as a whole atomically

That issue also says the problem is "not reproducible on iOS", where editing "removes the whole mention range instead of leaving orphaned plain text". Reading the current source, that does not seem to be the case: MentionStyle.remove:withDirtyRange: is commented // Strip meta only and calls removeAttribute:MentionAttributeName. The attribute goes; the characters stay.

Steps to reproduce
  1. In an EnrichedTextInput with mentionIndicators={['@']}, insert a mention with setMention('@', '@Jane Doe', { id: '42' }).
  2. Place the caret in the middle of the name and type one character — or let iOS autocorrect the name, which hits the same path.
  3. Read onChangeHtml.

Expected: the mention is untouched (the character landing beside it), or it is removed whole.
Actual: <p>@Jane Dxoe</p> — plain text, no <mention>, no id.

A backspace inside the name does the same thing: one character disappears, and the mention silently stops being one.

Where it comes from

shouldChangeTextInRange:replacementText: consults no mention at any point, so every edit is accepted; handleExistingMentions then compares each mention's stored text to what the storage now holds, and drops the attribute when they differ.

Autocorrect is the worst case: it rewrites a proper noun without the user doing anything deliberate, and there is no way to opt out for a range — autoCorrect (added in 1.2.0, thanks!) is per-input, so turning it off to protect mentions also turns it off for the whole document.

Possible fix

Hold the rule where edits arrive, in shouldChangeTextInRange:replacementText::

  • the modified range intersects a mention, and the replacement is empty → remove the whole mention (plus the space setMention appended) and return NO;
  • it intersects a mention and the replacement is not empty → return NO.

For a collapsed caret, only strictly inside should count — on either edge the character legitimately belongs beside the mention.

One detail worth noting for whoever implements it: -attribute:atIndex:longestEffectiveRange: fills the range even when the attribute is absent, so a zero-length range is not the signal it appears to be. getMentionParamsAt: returning nil is the reliable check.

I have this running as a local patch against 1.2.0 and I am happy to open a PR if the approach suits you.

Version

react-native-enriched-html 1.2.0, React Native 0.86.3, iOS.

主要语言
C
星标
1.4k
派生
76
平均合并
3 天 10 小时
30 天内合并 PR
23

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

software-mansion/react-native-enriched-html 的其他 Issue

查看 software-mansion/react-native-enriched-html 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。