Skip to content

Releases

0.6.1 — 有选区时右半边也包裹;Ctrl+Z 一次撤掉整对

Choose a tag to compare

@lov0vo lov0vo released this 03 Nov 05:03

0.6.1(内部 v10)

修两个输入法场景下的老问题:选中文字后按符号「有概率」被替换、Ctrl+Z 只撤掉一边的符号。

1. 选中文字后按符号被替换

中文输入法在已经有引号的状态下按引号键,提交的是右引号 ”;而包裹分支的条件写死成「提交的是左半边」(isOpen),右引号被挡到「补一对」那条路上 —— 那时原文已经被输入法删掉了,于是表现为「选中的文字被替换成一个右引号」。左括号那种(输入法给 ()走得到包裹,所以是「有概率」。

  • 新增 wrapPairFor() / openerForClose():左半边右半边都能反查出完整的一对()→(、”→“)。
  • wrapCommittedOpenInEditor 泛化为 wrapCommittedSymbolInEditor(editor, committed, open, close, snapshot)。
  • onCompositionEnd 的包裹分支改成「只要能配成一对就还原成包裹」;planInsert / planFromSelection 在「有选区 + 按右半边」时也返回 wrap(DOM 兜底路径同样受益)。
  • 顺带放宽 readTextSelection / isTextOnlySelection:Lexical 编辑中会把文本节点拆开重建,旧判据(同 key、同父节点)会把跨节点选区误判成「不可包裹」,从而放行浏览器默认的「替换选区」。

2. Ctrl+Z 只撤掉一边

输入法提交的左半边是浏览器自己插的(历史条目 1),我们补的右半边是第二次 editor.update()(历史条目 2)→ 撤销只回退到「只有左半边」。

现在输入法链路上的所有模型层更新(补右半边、包裹原文、引号再嵌一对、跳过重复右半边)统一带 { tag: ['history-merge'] },Lexical 会把它们并进「输入法提交」那一条历史记录 —— 一次 Ctrl+Z 就能把符号与原文整体回退。直接打字(beforeinput)的路径不带这个标签,保留逐步撤销。

升级

cd dsh-composer-autopair
git pull
node build.mjs && node deploy.mjs

装好后不用重启 DSH(客户端插件热重载)。报告里 version 变成 v10、caps.composerReady === true 即生效。

测试

单测 80 → 88:右半边 + 有选区 → 包裹、输入法提交右引号/右括号 → 包裹、跨文本节点选区仍能读出原文、两条 history-merge 断言。

0.6.0 — 问答卡片的输入框也支持配对

Choose a tag to compare

@lov0vo lov0vo released this 27 Oct 12:24

新功能:DSH 问答卡片里的输入框也支持配对

AskUserQuestion 那种问答卡片(标题 + 说明 + 输入框 + 跳过/下一题)里的输入框是个普通 <textarea>
(React 受控组件),既不是 contenteditable 也不是 Lexical —— 之前完全不在插件的作用范围内,所以在那
里打括号不会配对。0.6.0 把它纳进来了。

覆盖范围

操作 结果
输入 ( ( “ … 补右半边,光标停在中间
选中文字再输入左半边 包住原文并选回原文
右半边已在右边时再按右半边 越过它,不多打一个
空引号对中间再按引号键 再嵌一对
在空对中间按退格 两个一起删掉
中文输入法提交 ( 同样补右半边
输入法把选中的文字替换掉 还原成「包住原文」

只认问答类输入框(旁边有 aria-hidden 镜像 div,或类名带 fieldInput),终端、命令面板等别的
textarea 一律不碰;本机还有别的输入框想纳入,往 localStorage 的 dsh-composer-autopair:textareas
写逗号分隔的选择器。

诊断

stats.viaTextarea、caps.answerTextareas、trace 里的 ta-* 事件,都能从磁盘上的 localStorage
报告里读到(node tools/read-report.mjs)。

单测 65 → 80。

升级 / 安装

cd dsh-composer-autopair
node deploy.mjs          # 已在装的话再跑一次就是升级(客户端插件热重载,不用重启 DSH)

新装:dsh plugin add github:lov0vo/dsh-composer-autopair,或按 README 的「安装」一节选路线。

0.5.3 — 输入法包裹选区:不再比对会被重建的节点身份

Choose a tag to compare

@lov0vo lov0vo released this 22 Oct 08:47

中文

修 0.5.2:真实编辑器里「选中文字再按符号」仍然被替换 —— 判据用了会被重建的节点身份。

0.5.2 加了「输入法把选区替换成符号后,把原文包回来」的逻辑,但它在真实编辑器里没生效:
诊断报告显示原文已经抓到了(cs)、提交字符也收到了(ce),最后却走了「补一对」分支。

  • 根因:改写前的守卫要求「提交后的文本节点 key 与组合开始时一致,且偏移等于起点 + 符号长度」。
    Lexical 删掉选区时会把文本节点拆开重建,key 已经变了、偏移也随节点切分失效,于是守卫
    永远不通过。
  • 修法:判据只留「光标左边紧挨着刚提交的那个符号」;另加一条防守——原文还紧挨在符号左边时
    说明选区其实没被替换,直接放弃,避免把文字复制两遍。
  • 诊断:失败原因记进 trace 的 wrap-miss(no-caret / no-char / not-replaced /
    no-writer / no-range),下次出问题能一眼定位。
  • 单测 63 → 65(新增:节点 key 被重建仍要包裹;原文没被替换时不重复塞一遍)。

升级

  • 市场安装:dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
  • 本机已有:重新 node deploy.mjs 即可;客户端插件热重载,不需要重启 DSH
  • 自检:localStorage 的 dsh-composer-autopair:probe 会显示 v8 loaded <时间>,报告里的
    version 应为 v8、stats.imeWrapped 在包裹成功时递增

English

Fixes 0.5.2: "select text, then press a symbol" was still replaced in the real editor, because the
guard compared node identity that Lexical re-creates.

  • Root cause: the guard required the post-commit text node key to match the one captured at
    compositionstart, plus an exact offset. Lexical rebuilds the text node when it deletes a
    selection, so the guard could never pass.
  • Fix: the only requirement now is "the symbol just committed sits immediately left of the caret",
    plus a guard that bails out (not-replaced) if the original text is still there, so the text is
    never duplicated.
  • Diagnostics: failures are recorded as wrap-miss in trace with a concrete reason.
  • Tests 63 → 65.

Upgrade: node deploy.mjs (client plugins hot-reload, no restart needed). Market install:
dsh plugin --profile web add github:lov0vo/dsh-composer-autopair.

0.5.2 — 输入法选中文字后按符号:包住原文而不是替换

Choose a tag to compare

@lov0vo lov0vo released this 22 Oct 08:49

中文输入法下选中一段文字再按符号,不再把原文替换掉,而是包住原文。
With a Chinese IME, selecting text and then typing a symbol now wraps the selection instead of
replacing it.

  • 根因:输入法提交符号时,浏览器先把选中的文字删掉、再插入它自己提交的那个字符;等
    compositionend 到达时原文已经没了,插件只能看到「光标左边多了一个 (」,于是按「补一对」
    处理 —— 原文被替换成了 ()。The IME deletes the selection before committing, so by the time
    compositionend arrives the selected text is already gone and the plugin could only see the
    freshly committed bracket.
  • 修法:在 compositionstart(以及 beforeinput 的 insertCompositionText,兜底那些先删选区
    再发事件的浏览器)把选区原文记下来;compositionend 确认提交字符落进模型后,把光标左边
    那个符号改写成 open + 原文 + close,并把原文重新选中 —— 与直接打字时的包裹表现完全一致。
    The selection text is captured before the IME destroys it and re-applied as a wrap on commit.
  • 位置对不上(普通插入而不是替换选区)时不动,交给原来的「补右半边」逻辑。
  • 诊断:新增 stats.imeWrapped,trace 记 cs / bi-cs / wrap-ime。
  • 单测 55 → 63(新增 4 个:全角/半角包裹、无选区不误判、非配对字符不插手)。

安装 / Install:dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
本机更新 / Local update:node deploy.mjs(客户端插件热重载,无需重启 DSH)

0.5.1 — 修复 0.5.0 回归:读不到模型光标时不再什么都不补

Choose a tag to compare

@lov0vo lov0vo released this 22 Oct 08:49

修复 0.5.0 的回归:中文输入法下所有符号都不成对了(只出一个)。
Fix for a 0.5.0 regression: with a Chinese IME no symbol paired up at all.

  • 根因:0.5.0 把 currentCaret() 当成主判据,而它在 Lexical 的读取上下文之外裸调
    point.getNode() —— 真实 Lexical 里这会抛「找不到活动编辑器状态」(Unable to find an active editor state),异常被吞掉后表现为「永远读不到光标」:轮询一路超时,每次输入法
    提交都记 imeNotSettled,于是什么都不补。In 0.5.0 currentCaret() called
    point.getNode() outside a Lexical read context; real Lexical throws there, the error was
    swallowed, the poll timed out every time and nothing was ever paired.
  • 修法一:currentCaret() 改在 editorState.read(...) 里取节点,模型探针重新可用。
    Now reads the node inside editorState.read(...).
  • 修法二:任何情况下都不再「什么都不做」——读不到模型光标(trace 记 ce-nocaret)或等满
    12 帧仍没吸收(trace 记 ce-stale)时,立刻回退到 DOM 兜底路径补全。A DOM fallback now
    covers both the unreadable-caret and never-absorbed cases.
  • 单测 55 → 58:新增「必须在读取上下文里取节点」(模拟真实 Lexical,裸调即抛错)、
    「读不到光标 → 立刻 DOM 兜底」、「一直没吸收 → 12 帧后 DOM 兜底」。

安装 / Install:dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
本机更新 / Local update:node deploy.mjs(客户端插件热重载,无需重启 DSH)

0.5.0 — 中文输入法下引号每次都要成对

Choose a tag to compare

@lov0vo lov0vo released this 22 Oct 08:49

修复:中文输入法下引号每次都要成对,不再「第一次成对、第二次只出一个」。
Fix: with a Chinese IME, quotes now pair up every time instead of only the first time.

  • 根因:compositionend 到达时 Lexical 还没把这次提交写进模型,DOM 探针也还停在提交前。
    旧实现只等一帧、且完全依赖 DOM 探针,对不上就整段放弃 → 第二次按引号键提交的右引号
    孤零零留在正文里。The committed character lands in Lexical's model a frame or two after
    compositionend; the old code waited a single frame on a DOM-only probe and gave up
    entirely when it did not match, leaving a lone closing quote behind.
  • 改成轮询模型:每帧检查这次提交是否已经落到光标左边,最多等 12 帧;
    超时就记 imeNotSettled 并什么都不做(宁可不动,也绝不删输入法刚提交的字符)。
    Now polls the model for up to 12 frames; on timeout it records imeNotSettled and
    deliberately does nothing rather than risk deleting what the IME just committed.
  • 删掉了那条会误伤嵌套的 DOM 守卫(nestQuoteInEditor / skipCommittedCloserInEditor
    自己会校验光标右边是不是同一个右半边)。Removed the DOM guard that mis-fired on nesting.
  • 新增一条兜底:提交的右引号左边没有任何等着收尾的左引号时(典型场景:光标停在一对
    已经有内容的引号之后,输入法却按自己的节奏给了右引号),把它就地改写成一对,
    光标停在中间 —— 这样「无论怎么输入引号都成对」。左边真有没收尾的左引号时不动它,
    那才是正常收尾。A committed closing quote with no unmatched opening quote to its left is
    rewritten into a fresh pair, so quotes pair up no matter what the IME emits.
  • 新增 trace(最近 24 条事件流水:bi / bi-other / kd / ce / ce-dom / ce-stale /
    dup / pair / nest / skip / noop),随诊断报告一起落盘,事后能还原现场;
    api.trace 也可直接读。A 24-entry event trace now ships inside the diagnostic report.
  • 新增 6 个用例(模型晚一拍 / 连按引号键 / 输入法始终提交左引号 / 已有内容的一对之后 / 正常收尾不受影响 / trace 落盘);单测总数 49 → 55(客户端 41 → 47)。

安装 / Install:dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
本机更新 / Local update:node deploy.mjs(客户端插件热重载,无需重启 DSH)

0.4.1 — 同一个 loader id 不再挂两层

Choose a tag to compare

@lov0vo lov0vo released this 22 Oct 08:50

修复:同一个 loader id 不再挂两层。
Fix: the same loader id is no longer mounted twice.

  • deploy.mjs 现在按 profile 现状二选一挂 Loader 条目:profile 的 dsh.profile.bundles
    里已登记本包 → 走 bundle 路线,并把 user-patch 里的托管块删掉;否则才在
    cordis.patch.yml 里插一行。两条都插会让 composer-autopair 出现 2 行,
    dshmarket 安装/更新插件后的「组合能否启动」检查会判成重复条目并自动回滚整次更新。
    deploy.mjs now picks exactly one mounting route and never leaves both rows behind.
  • 托管块改成摘掉全部(旧版只摘第一个,重复运行会留下两行)。
    The managed block is now stripped in full, not just its first occurrence.
  • file: 依赖改为指向稳定副本 <DSH_HOME>/plugins/dsh-composer-autopair,不再指向仓库目录:
    仓库换位置时旧写法会变成悬空依赖,被 pnpm install 清掉后插件静默失效。
    The file: dependency now points at a stable copy under <DSH_HOME>/plugins/.
  • --remove 顺带摘掉 dsh.profile.bundles 里的登记,不留悬空条目。
  • 新增 src/deploy.test.mjs(8 个用例:块摘除 / 路线选择 / 两条路线各装一遍 / --check 不写盘 / 卸载);单测 41 → 49。

安装 / Install:dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
本机更新 / Local update:node deploy.mjs(客户端插件热重载,无需重启 DSH)

0.4.0 — 首个公开版本

Choose a tag to compare

@lov0vo lov0vo released this 22 Oct 08:50

修复:引号不再「跳过去」,而是再嵌一对。
Fix: quotes now nest instead of skipping.

  • 已有一对引号(“” / "")时,光标在中间再按引号键 → 再嵌一对(““””)。
    Chinese IMEs emit the closing quote after an opening one, which used to hit the "skip over the
    closing half" rule and made nesting impossible.
  • 「跳过」按「这一对是不是空的」拆开:空的一对 → 嵌一对;已有内容 → 仍然跳过收尾。
    Skip vs. nest now depends on whether the pair is empty; a pair with content still just closes.
  • 括号不受影响。Brackets are unaffected.
  • 新增计数 nested;单测 36 → 41。

安装 / Install:dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
本机更新 / Local update:node deploy.mjs(客户端插件热重载,无需重启 DSH)