Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rime_api): add RimeApi::set_input #771

Merged
merged 1 commit into from
Dec 17, 2023
Merged

Conversation

imfuxiao
Copy link
Contributor

@imfuxiao imfuxiao commented Dec 1, 2023

Pull request

新增 api 用于调整用户已输入的字符。

Issue tracker

Feature

resolve #547

Unit test

  • Done

Manual test

  • Done

Code Review

  1. Unit and manual test pass
  2. GitHub Action CI pass
  3. At least one contributor reviews and votes
  4. Can be merged clean without conflicts
  5. PR will be merged by rebase upstream base

Additional Info

Copy link
Contributor

@groverlynn groverlynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a special case covered by set_input. There is no point to add this function

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 4, 2023

This is just a special case covered by set_input. There is no point to add this function

类中文九宫格输入方案,需要替换用户输入的模糊串。比如输入“426 23”,可以是 “hao de”, 也可以是 “gan de”。

此时需要一个api 替换其中已经输入的串。具体见 issue #547

@mokapsing
Copy link
Contributor

这个和set_input的区别在于部分替换吗?那完全可以自己外部实现

string input_cpy = context.input;
input_cpy.replace(pos, count, value);
context.set_input(input_cpy);

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 7, 2023

这个和set_input的区别在于部分替换吗?那完全可以自己外部实现

string input_cpy = context.input;
input_cpy.replace(pos, count, value);
context.set_input(input_cpy);

您好,我对 rime 不了解,rime_aip.h 我没找到修改 input 的 api。所以加了这个。

另外。如您说的 set_input 当然可以,但我觉的,replace_input 也可以,也有更多的选择项,仅个人意见。

Copy link
Member

@eagleoflqj eagleoflqj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来问题的症结不在缺一个replace的功能,而是set_input没有导出rime api。能否去掉replace_inputRimeReplaceInput,而是实现一个RimeSetInput

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 7, 2023

看起来问题的症结不在缺一个replace的功能,而是set_input没有导出rime api。能否去掉replace_inputRimeReplaceInput,而是实现一个RimeSetInput

那我重新修改下,只导出 set_input 是否可以呢?

@mokapsing
Copy link
Contributor

这个和set_input的区别在于部分替换吗?那完全可以自己外部实现

string input_cpy = context.input;
input_cpy.replace(pos, count, value);
context.set_input(input_cpy);

您好,我对 rime 不了解,rime_aip.h 我没找到修改 input 的 api。所以加了这个。

另外。如您说的 set_input 当然可以,但我觉的,replace_input 也可以更多的选择项,仅个人意见。

set_input没有导出,我个人认为添加导出就够了,set_input应该能满足replace的需求

@mokapsing
Copy link
Contributor

看起来问题的症结不在缺一个replace的功能,而是set_input没有导出rime api。能否去掉replace_inputRimeReplaceInput,而是实现一个RimeSetInput

那我重新修改下,只导出 set_input 是否可以呢?

我个人非常赞同,九宫格方案确实需要这个接口

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 7, 2023

看起来问题的症结不在缺一个replace的功能,而是set_input没有导出rime api。能否去掉replace_inputRimeReplaceInput,而是实现一个RimeSetInput

那我重新修改下,只导出 set_input 是否可以呢?

我个人非常赞同,九宫格方案确实需要这个接口

好的,我重新修改后,在提交。

@lotem
Copy link
Member

lotem commented Dec 7, 2023

九宮格選擇拼音僅僅替換輸入碼還不夠。需要同時添加輔助切分音節的信息。

@mokapsing
Copy link
Contributor

基于rime ios粤语输入法写了个插件,主线如果暂时不收,你可以看下那个

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 8, 2023

基于rime ios粤语输入法写了个插件,主线如果暂时不收,你可以看下那个

仓输入法已经使用之前 replace_input api 实现了候选拼音选择。如果主线分支合并了,我这边会在改为 set_input

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 8, 2023

九宮格選擇拼音僅僅替換輸入碼還不夠。需要同時添加輔助切分音節的信息。

目前是通过模糊输入+精确替换来实现的。

模糊输入使用数字穷举了全部的拼音组合。这部分也在九宫格的输入方案中进行了配置。

前端内置的也有穷举后的拼音组合。候选拼音可通过 set_input 替换已输入的模糊数字,将模糊数字替换为候选的精确拼音。

目前测试一切正常。

@mokapsing
Copy link
Contributor

基于rime ios粤语输入法写了个插件,主线如果暂时不收,你可以看下那个

仓输入法已经使用之前 replace_input api 实现了候选拼音选择。如果主线分支合并了,我这边会在改为 set_input

https://github.com/Cantoboard/librime-cantoboard.git 他们是做了个插件,像gram和lua一样

@imfuxiao
Copy link
Contributor Author

imfuxiao commented Dec 8, 2023

基于rime ios粤语输入法写了个插件,主线如果暂时不收,你可以看下那个

仓输入法已经使用之前 replace_input api 实现了候选拼音选择。如果主线分支合并了,我这边会在改为 set_input

https://github.com/Cantoboard/librime-cantoboard.git 他们是做了个插件,像gram和lua一样

收到,感谢

@lotem
Copy link
Member

lotem commented Dec 8, 2023

九宮格選擇拼音僅僅替換輸入碼還不夠。需要同時添加輔助切分音節的信息。

目前是通过模糊输入+精确替换来实现的。

模糊输入使用数字穷举了全部的拼音组合。这部分也在九宫格的输入方案中进行了配置。

前端内置的也有穷举后的拼音组合。候选拼音可通过 set_input 替换已输入的模糊数字,将模糊数字替换为候选的精确拼音。

目前测试一切正常。

替換拼音串無法解決已經經過用戶確認的拼音音節被再次切分的問題。
如:選擇拼音「xian」之後,還會被切分成「xi'an」。
這是因爲記錄的信息不全。

我有完整的解決方案,但還需要一段時間把代碼寫出來。你先用臨時的方法頂着。

@groverlynn
Copy link
Contributor

这个和set_input的区别在于部分替换吗?那完全可以自己外部实现

string input_cpy = context.input;
input_cpy.replace(pos, count, value);
context.set_input(input_cpy);

您好,我对 rime 不了解,rime_aip.h 我没找到修改 input 的 api。所以加了这个。

另外。如您说的 set_input 当然可以,但我觉的,replace_input 也可以,也有更多的选择项,仅个人意见。

你需要注意C String是null terminated的,而且utf8是可變長度,隨意替換容易產生非法字符導致rime崩潰,然而最終使用的新分配的內存字節數甚至是一樣的,代碼反而更繁瑣

Copy link
Member

@lotem lotem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lotem lotem changed the title feat: rime_api add RimeApi::RimeReplaceInput feat: rime_api add RimeApi::rime_set_input Dec 17, 2023
@lotem lotem changed the title feat: rime_api add RimeApi::rime_set_input feat(rime_api): add RimeApi::rime_set_input Dec 17, 2023
@lotem lotem changed the title feat(rime_api): add RimeApi::rime_set_input feat(rime_api): add RimeApi::set_input Dec 17, 2023
@lotem lotem merged commit de12d6a into rime:master Dec 17, 2023
8 checks passed
groverlynn pushed a commit to groverlynn/librime that referenced this pull request Dec 19, 2023
fxliang pushed a commit to fxliang/librime that referenced this pull request Feb 2, 2024
graphemecluster pushed a commit to TypeDuck-HK/librime that referenced this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

如何修改已经输入的编码?
5 participants