Repository navigation
feat(cmdbar): dict.rev 省略 n 时整串反查(复制一个词就查这个词的码) - #259
Open
Lovepeace-art wants to merge 1 commit into
Open
Lovepeace-art wants to merge 1 commit into
Lovepeace-art wants to merge 1 commit into
Conversation
剪贴板反查(出厂 `cofc`)此前只能查剪贴板的第 1 个字:`dict.rev(text, n)` 硬编码
`.chars().nth(n - 1)`,而宿主侧 `EvalContext::reverse_lookup(text, format)` 本就收任意
文本,`reverse_render` → `eval_text_var` 走的 `codetable_reverse_hint` /
`word_codes_display` 也是**按词条**查主码表反向索引。唯一的拦路点就是那句挑字。
于是把「给没给 n」定义成两种用法,而不是新增函数:
- 省略 n → 整串交给宿主:复制「好吧」得到「好吧」这个词的码,单字自然落回单字;
- 给了 n → 取第 n 个字(1 起),`$SS` 逐字展开的写法一字不改。
逐字列表替代不了整串:形码的词级简码/容错码拼不出来,而那正是「这词怎么打」最想要的
答案;逐字还把一个查询摊成 N 条候选。保留 n 而非删掉——删了会让已在用的 `$SS` 词条静默
失效(参数个数超上界 → 整条短语连候选一起消失,用户零提示)。
同步:出厂 `cofc` 的注释块、`docs/design/clipboard-reverse-lookup.md`(含新增的「为什么
省略 n 就是整串」一节)、以及三处依赖「只查第 1 个字」的测试(含 coordinator 侧出厂短语
守门 `builtin_reverse_phrase.rs`)。纯空白剪贴板在整串模式下直接返回空串,免得 `${char}`
把换行回显成一条候选。
真实词库实测(wubi86 + 已装 data,headless 协调器):`好` → `好: vb/vbg hǎo`、
`你好` → `你好: wqvb nǐ hǎo`、`好吧` → `好吧: vbkc hǎo ba`。
This branch has not been deployed
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.
变更说明
现状:复制反查(出厂
cofc,以及各方案直通词库里的ofi之类)只能查剪贴板第一个字的编码。原因在命令层:
dict.rev(text, n)省略n时把 n 当 1,只取第 1 个字交给宿主反查;而宿主侧EvalContext::reverse_lookup(text, format)本来就收任意文本,${code_rev_all}走的word_codes_display也是整词接口。缺的只是「把整串交出去」这一步。本 PR 把「省略 n」的语义改成整串反查:
dict.rev(clip())dict.rev(clip(), 1)、dict.rev(s, 2)要点:
cofc、用户既有的$SS("反查", "{dict.rev(clip(),1)}", …)逐字写法都不受影响—— 只有省略 n 的调用方语义变了,而那正是「查不到词」的那批写法。
""/ 纯空格 / 制表 / 换行)直接返回空串,由词条里的default(...)显示提示语,与「点候选时剪贴板为空」表现一致。
default(反查结果, 提示语)的既有形态。(设计口径见
docs/design/text-code-lookup.md§2)。附带同步:
docs/design/clipboard-reverse-lookup.md:签名表改为整串,新增「为什么省略 n 就是整串」小节(逐字替代不了整串的三条理由:形码词级简码/容错码拼不出、逐字摊成 N 条候选、宿主侧无需改动)。
data/system.phrases.toml:cofc上方注释块改「字或词」,$SS示例标注为「逐字列举」并补 format 写法。rev_*用例改为整串语义,新增explicit_n_still_picks_that_char、whole_text_blank_yields_empty;coordinator / phrase 两个下游用例的剪贴板样本从「好人」改成「好吧」(「好人」不是词库词条,测不出整词码)。
变更类型
dict.rev省略n时的默认语义,词条与宿主侧均无需改动)相关 Issue
Fixes #258
issue 里另外两条建议(把通配输入与反查的开关分开、让
ofi直通词库统计/词库编辑)是另一个量级的改动,不在本 PR 范围内;本 PR 只解「复制反查只能查第一个字、查不到词」这一半。
测试情况
cargo test -p wind-cmdbar:153 passed;rev_过滤 7 passedcargo test -p wind-phrase:37 passed;clipboard_reverse过滤 2 passedcargo test -p wind-coordinator --test builtin_reverse_phrase:3 passedcargo clippy -p wind-cmdbar -p wind-phrase --all-targets:干净;改动文件rustfmt --check干净真实词库实测(五笔 86 词库):
好→好: vb/vbg hǎo;好吧→好吧: vbkc hǎo ba;我们→我们: trwu wǒ men真机验证:本机把 release 构建换进日常使用的输入法实例(flypy 方案,
ofi词条),复制「好吧」打
ofi得到整词码;服务日志与 IPC 均正常cargo test -p wind-coordinator --lib:1345 passed / 2 failed,失败的是handle_candidate::expand_stop_tests::expansion_that_shrinks_the_list_clamps_page_and_selection与
::expansion_continues_past_an_all_filtered_batch(panic 于handle_candidate.rs:8467)。用
git stash回到未改动的upstream/main重跑同样失败,属既有问题,与本 PR 无关。已在 Windows 10/11 上测试(Windows 11,MSVC/VS2022 工具链)
已在 macOS 上测试(如涉及)
已测试相关输入方案(五笔、flypy 双拼)
.\scripts\dev.ps1 ci通过(fmt 检查 + clippy + 测试)—— 逐项跑过:fmt/clippy 干净、上述用例全过;全 workspace 的
ci因上面两个既有失败拿不到全绿检查清单
cargo fmt格式化(逻辑修改与 fmt 修改分开提交)AGENTS.md—— 未改对外签名与文件结构,只需同步设计文档,已在
docs/design/clipboard-reverse-lookup.md完成兼容性说明
dict.rev(s)与dict.rev(s, 1)从此语义分叉:前者整串、后者第 1 个字。所有显式给了 n 的既有词条(包括出厂注释里的
$SS逐字示例)行为不变;只有原本指望「省略 n = 第 1 个字」的自定义短语会改变表现,而那种写法正是本 PR 要替换掉的。