Repository navigation
fix(composer): keep an empty last line without a phantom character - #2589
Conversation
Chromium inserts the break plus a placeholder newline after the caret, so one Enter reached the draft as two lines, and the zero-width space that held the empty last line was a real character: it could be selected and copied, some fonts drew it as a space, and re-syncing it rewrote the text node under the caret, which moved the caret off the end of the draft. The editor paints a <br data-composer-tail> placeholder instead and counts it as zero characters in every read, index and caret path, and it owns the break so a native insertLineBreak or insertParagraph becomes exactly one newline. A real-Chromium regression drives the production composer with keyboard input for the tail scenarios (vastsa#2433). closes vastsa#2555
|
在 Windows / Electron 43.6.0 独立验证了这个修复:原始 main 三行输入会画出四行并含 U+200B,你的 有一个可复现的行为回退:草稿 已在保留作者改动的本地候选验证了一个小补充:文中用原生 |
The end-of-draft break was inserted with a raw DOM mutation, so Chromium had no edit history for it and Undo left the newline behind (vastsa#2589 review). The break is now one native edit that inserts the real break together with the layout placeholder, and undo/redo take both nodes in a single step. A break anywhere else stays native: Chromium only adds its extra layout newline when the caret ends the block, so only that case is owned. The regression drives Undo, Redo, typing after Redo, consecutive end-of-draft breaks and a middle break through real key events. Refs vastsa#2588
|
@Tioit-Wang 已按建议补齐,只改了换行那一处,方案整体不变(commit 实现
验证(
输出: 其他: 未覆盖:独立 Window Station 的剪贴板回读,以及重打包后的 NSIS/portable 安装验证——这两项我这边没有对应环境(本机无 Rust 工具链)。其余路径已按上面的真实按键序列覆盖,麻烦复核。 |
Summary / 概要
#2554 用零宽空格给空末行做占位,但它是真实字符:可被选中、可被复制,字体缺 U+200B 字形时还被画成空格;每次提交还会改写光标所在的文本节点,于是尾部输入/删除时光标跳到开头。同时 Chromium 在光标位于块尾时会额外插入一个"占位换行",一次 Enter 就让草稿多一行。
本 PR:
<br data-composer-tail>占位:只提供行盒;读值、索引、光标三条路径一律计 0 个字符,因此不可选中、不可复制、不可键入,也不再改写任何文本节点;editorCaretPoint:草稿末尾的光标落在占位之前(空行行首),占位真正接住末尾光标(之前它被放到最后一个<br>之后);insertLineBreak/insertParagraph保持原生;文末由一次原生编辑(insertHTML)同时插入真实<br>与零长度<br data-composer-tail>,两者同进同出撤销栈(对应 fix(composer): keep an empty last line without a phantom character #2589 review 的撤销回退);onBeforeInput分支(React 19 不派发beforeinput,实测回调 0 次,是死代码)。Requirement link / 需求关联
Refs #2433, #2555
Verification / 验证
真实 Chromium 回归(
pnpm test:e2e:composer-tail-line):Electron 43(Chromium 150)里挂载生产useComposerDraft+useComposerCompletions+ComposerInput,用 CDP 下发真实按键(含Ctrl+Z/Ctrl+Y)并断言几何:1test↵2test↵3test1test\n2test\n3test,3 个行盒,光标在末尾1test\n\n2test\n3test,4 个行盒,光标在 index 6(新空行)[5, 6, 12, 18],第 5 行不存在Ctrl+Z1test\n\n2test\n3test,行盒减 1,光标停在末尾Ctrl+Y→ 输入zz落在这一空行上Ctrl+Z输出:
{"ok":true,"clicks":[5,6,12,18],"last":{"value":"1test\n\n2test\n3test\nz\n\n\n","caret":20,"lineTops":[20,40,61,81,101,121,142,162],"invisibleChars":[]}}其他检查:
tsc -p apps/desktop/tsconfig.json --noEmit:composer 相关文件无错误;biome lint(变更文件)通过;node --test apps/desktop/test/composer-*.test.mjs:288/289,唯一失败是composer-file-references.test.mjs在未开发者模式的 Windows 上symlink报 EPERM(环境限制,与本改动无关);main(69e52eec0),check:pr-base通过。Undo / 撤销
<br>+ 零长度占位),Ctrl+Z一次撤掉整行,Ctrl+Y恢复后可以继续在该行输入;insertLineBreak,同样可撤销;编辑器只在文末接管;Specs / 规格
docs/spec/04-ux/08-component-spec.md:空末行占位、文末换行归属与撤销语义已同步。