Repository navigation
fix(input): 写回前不比对框的长度上限,原生插入把超出 maxlength 的部分静默截掉 → 译文装不下时不写回,框里留原文、译文走提示条,刚好装得下照常替换(#654) - #700
Merged
Merged
Conversation
…译文走提示条,刚好装得下照常替换(#654) Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
Co-Authored-By: zhexuancai-uts <261878103+zhexuancai-uts@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
输入翻译的译文比输入框的长度上限(
maxlength)长时,写回后超出的部分被浏览器静默截掉。框里留下半句译文,用户可能直接把半句话发出去,比不翻更糟。这违反 ADR-0005 的出发点:宁可不猜,也不要让用户把一段不对的文字发出去。根因
写回走浏览器原生插入(
execCommand('insertText')),插入受maxlength约束,超出部分直接丢弃且不报错。写回判定decideWriteBack()只看原文快照与焦点(#646),代码里没有任何长度上限的处理。修复
decideWriteBack()新增两项显式输入:translation(要写回的译文)与maxLength(框的长度上限,没有时为null){ write: false, reason: 'too-long' };长度按浏览器的口径数 UTF-16 码元inputMaxLength():单行与多行输入框读maxLength(没写时浏览器给 -1,记为null);contenteditable 没有 maxlength,恒为null,本票对它不生效验证
input-writeback.test.ts新增 5 条,修复前红 3 条,另 2 条是照常写回的回归保护pnpm test114 个文件 1412 条全绿;pnpm typecheck通过;pnpm build通过pnpm test:e2e:core88 过、2 跳过、1 不稳定:TC-E2E-126 是 DeepL 打桩加整页翻译的路径,与本票无关,重试通过,单独连跑 5 次都过Closes #654