4
9
Fork
You've already forked libchewing
3

Can't reliably clean all buffer with chewing_clean_preedit_buf & chewing_clean_bopomofo_buf #715

Closed
opened 2025年07月26日 00:10:40 +02:00 by wengxt · 4 comments
wengxt commented 2025年07月26日 00:10:40 +02:00 (Migrated from github.com)
Copy link

Describe the bug
In fcitx, we have been using following function to reset chewing into an empty state. (Not sure why I'm not using chewing_Reset, maybe because it was not originally available?....I'll update fcitx to use it anyway. )

 chewing_cand_close(ctx);
 chewing_clean_preedit_buf(ctx);
 chewing_clean_bopomofo_buf(ctx);

But now it seems to can't clear when there's both preedit & bopomofo

To Reproduce

Steps to reproduce the behavior:
z p space z, and run the code above.

Expected behavior
nothing left in chewing context.

Platform (please complete the following information):

  • OS: Arch
  • IME: fcitx5-chewing
  • Version 0.9.1

Additional context
Add any other context about the problem here.

**Describe the bug** In fcitx, we have been using following function to reset chewing into an empty state. (Not sure why I'm not using chewing_Reset, maybe because it was not originally available?....I'll update fcitx to use it anyway. ) ``` chewing_cand_close(ctx); chewing_clean_preedit_buf(ctx); chewing_clean_bopomofo_buf(ctx); ``` But now it seems to can't clear when there's both preedit & bopomofo **To Reproduce** Steps to reproduce the behavior: z p space z, and run the code above. **Expected behavior** nothing left in chewing context. **Platform (please complete the following information):** - OS: Arch - IME: fcitx5-chewing - Version 0.9.1 **Additional context** Add any other context about the problem here.
kanru commented 2025年07月26日 00:19:50 +02:00 (Migrated from github.com)
Copy link

It looks like the problem is in chewing_clean_preedit_buf(ctx);
Now it checks if the context is editing the preedit or the bopomofo.

These APIs are for UI-less scenario so it make sense to restore the original behavior and always clear the preedit.

It looks like the problem is in `chewing_clean_preedit_buf(ctx);` Now it checks if the context is editing the preedit or the bopomofo. These APIs are for UI-less scenario so it make sense to restore the original behavior and always clear the preedit.
kanru commented 2025年07月26日 00:47:35 +02:00 (Migrated from github.com)
Copy link

Previously the UI-less APIs are not very consistent in checking the state machine..

They check if selection was open but do not check if bopomofo is entering. I'll keep the pre-0.9 behavior and think about how to fix them.

Previously the UI-less APIs are not very consistent in checking the state machine.. They check if selection was open but do not check if bopomofo is entering. I'll keep the pre-0.9 behavior and think about how to fix them.
rocka commented 2026年01月19日 18:55:11 +01:00 (Migrated from github.com)
Copy link

@wengxt

Not sure why I'm not using chewing_Reset, maybe because it was not originally available?.

This API has been available since at least 2005: github.com/chewing/libchewing@2da97a5898

I think the actual reason not to use chewing_Reset before is, this API is meat to "Reset all settings" in older versions of libchewing

github.com/chewing/libchewing@9be48513bc/include/chewingio.h (L208-L214)

It would reset the layout set in chewing_set_KBType too.

However in newer versions of libchewing, the same API meat to "Reset the context but keep all settings"

github.com/chewing/libchewing@a6a8fa4abd/capi/include/chewing.h (L313-L324)

which caused very strange behavior with fcitx5-chewing 5.1.9+ and libchewing 0.8.5:

@wengxt > Not sure why I'm not using chewing_Reset, maybe because it was not originally available?. This API has been available since at least 2005: https://github.com/chewing/libchewing/commit/2da97a58984027fd6afa99f7a4193bc483f6b771 I think the actual reason not to use `chewing_Reset` before is, this API is meat to "Reset all settings" in older versions of libchewing https://github.com/chewing/libchewing/blob/9be48513bc46bafa134eef4b2bfde6a533470d33/include/chewingio.h#L208-L214 It would reset the layout set in `chewing_set_KBType` too. However in newer versions of libchewing, the same API meat to "Reset the context but keep all settings" https://github.com/chewing/libchewing/blob/a6a8fa4abd3f215e3ba89a7b61702eaf8ca68f5c/capi/include/chewing.h#L313-L324 which caused very strange behavior with fcitx5-chewing 5.1.9+ and libchewing 0.8.5: - https://github.com/fcitx5-android/fcitx5-android/issues/836
kanru commented 2026年01月20日 00:47:29 +01:00 (Migrated from github.com)
Copy link

@rocka I think it's a bug in the original C version

github.com/chewing/libchewing@e95e79edad/src/chewingio.c (L328-L329)

All configs except

  • bChiSym
  • bFullShape

are reset to their default value.

This is first introduced in 930d1f63a2 where we merged change from win32-utf8 branch and the definition of config diverged. The 2 runtime configs are still kept in ChewingData directly and they were reset to default by chewing_Reset, namely bChiSym, bFullShape,

I think unfortunately the kbtype was also part of the config that was reset because it was not part of the ConfigData structure.

@rocka I think it's a bug in the original C version https://github.com/chewing/libchewing/blob/e95e79edade76f55ea940457c873a4aa98bbec9c/src/chewingio.c#L328-L329 All configs except * bChiSym * bFullShape are reset to their default value. This is first introduced in 930d1f63a29820b7e0d65c953518a99e27842163 where we merged change from win32-utf8 branch and the definition of `config` diverged. The 2 runtime configs are still kept in `ChewingData` directly and they were reset to default by `chewing_Reset`, namely `bChiSym`, `bFullShape`, I think unfortunately the `kbtype` was also part of the config that was reset because it was not part of the `ConfigData` structure.
Sign in to join this conversation.
No Branch/Tag specified
master
release/0.13.x
push-qlrtqulwmpmp
push-wtuvoynpwosl
release/0.10.x
release/0.8.x
optimize-conversion
refactor-trie-loader
v0.13.0
v0.12.0
v0.12.0-alpha.1
v0.11.0
v0.11.0-alpha.1
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.9.0-rc.3
v0.9.0-rc.2
v0.9.0-rc.1
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.8.0-rc.4
v0.8.0-rc.3
v0.8.0-rc.2
v0.8.0-rc.1
v0.7.0
v0.7.0-rc.2
v0.7.0-rc.1
v0.6.0
v0.6.0-rc.2
v0.6.0-rc.1
v0.5.1
v0.5.0
v0.4.0
v0.3.5
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.7
v0.2.6
v0.2.5
v0.2.4
Labels
Clear labels
dictionary
duplicate
fixed
0.11.0

Archived

fixed
0.13.0
refactoring

Archived

rewrite in rust
Might be fixed by the rust rewrite
thirdparty
arch
aarch64
系統架構是 Aarch64
arch
x86_64
系統架構是 x86_64
cannot reproduce
無法重現問題 Cannot reproduce the issue
contribution welcome
歡迎來幫忙 Contributions are very welcome, get started here
duplicate
重複的問題回報 This issue or pull request already exists
good first issue
適合新手 Interested in contributing? Get started here.
help wanted
需要高手相助 Need some help
invalid
回報的問題無效 Something is wrong
kind
bug
有東西不正常運作 Something is not working
kind
doc
加強文件說明 Enhance documentation
kind
enhancement
新功能 New feature
kind
mega issue
同一個問題回報中包含多個問題 Multiple issues reported
kind
question
只是問問題 Asking a question
needinfo
需要更多資訊 More information is needed
os
apple
作業系統是 MacOS 或 iOS
os
linux
作業系統是 GNU Linux
os
windows
作業系統是 Windows
to be determined
還未被說服有需求 Can't decide whether this is needed
upstream
跟上游軟體相關 Related to an upstream repository, already reported there
wontfix
我們決定不處理 Won't be fixed
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chewing/libchewing#715
Reference in a new issue
chewing/libchewing
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?