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

CandidateReg set_text , set_preedit, set_comment 增加警告 #295

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

shewer
Copy link
Contributor

@shewer shewer commented Dec 16, 2023

cand.text , cand.preedit, cand.comment 無法設定時,輸出LOG(WARNING)

src/types.cc Outdated
@@ -118,20 +143,34 @@ namespace CandidateReg {
void set_text(T &c, const string &v) {
if (auto p = dynamic_cast<SimpleCandidate *>(&c))
p->set_text(v);
else if (auto p = (WrapShadow *) dynamic_cast<ShadowCandidate *>(&c))
Copy link
Owner

Choose a reason for hiding this comment

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

ShadowCandidate 并不是一种 WrapShadow,所以这个 cast 不对。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

改成 LuaShadowCandidate 呢?

Copy link
Owner

Choose a reason for hiding this comment

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

与名字没有关系。原来的对象是 ShadowCandidate 的实例,并不能安全地转换为 WrapShadow

Copy link
Owner

Choose a reason for hiding this comment

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

这里有一个巧合,是 WrapShadow 在内存中的布局恰好与 ShadowCandidate 一样了,所以表面上能工作。但实际上是不合法的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

這的確是我的動機 , 當初是想在 api 中方便操作 ShadowCandidate text ,comment

如果 只能 an to WrapShadow , 那麼就只能 在filter 中
先行置換 Shadow 了

1 在filter 中改 , 這個較易 取出 Phrase 重裝 Shadow or WrapShadow
2 在 onCommit 前 改 candidate text ,但是
沒有方法可以交換 Menu 中的成員 CandidateList
所以提供 Candidate 可以修改 text 較方便的方式

Copy link
Contributor Author

Choose a reason for hiding this comment

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

想到了 直接用 委任 類似 shadow 再上 委任接口 及 text , comment
那麼 就可以委任 shadow phrase Uniquified 了

@shewer
Copy link
Contributor Author

shewer commented Feb 7, 2024

  1. LuaShadowCandidate 取代 ShadowCandidate, LuaUniquifiedCandidate 取代 UniquifideCandidate, ,增加 write_able 以便於寫入 text comment preedit
  2. 增加 vars_get "dynamic_type" 等同 :get_dynamic_type()
  3. 增加 vars_get "dynamic_candidate" 可以取得 Phrase Sentence LuaShadowCandidate LuaUniquifiedCandidate

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.

2 participants