librime icon indicating copy to clipboard operation
librime copied to clipboard

Changing option via keyboard shortcut does not persist to user.yaml

Open russell-liu opened this issue 1 year ago • 3 comments

Describe the bug Changing (e.g. toggling) an option to be saved via the options menu successfully persists to user.yaml, and therefore persists when changing schemas or exiting and restarting Rime. The persistence fails when changing the option via a keyboard shortcut.

To Reproduce Below are high-level reproduction instructions on Weasel and detailed reproduction instructions with librime built from source on Linux (with build dependencies installed).

Weasel

session 1

  • choose any schema, A
  • use options menu to toggle any option
  • choose a different schema, B
  • choose A
  • verify that the option has been toggled

session 2

  • choose any schema, A
  • use keyboard shortcut to toggle any option
  • choose a different schema, B
  • choose A
  • verify that the option has not been toggled!!!

librime on Linux (input into shell)

N.B. full_shape is an option that needs to be saved session 1

git clone https://github.com/rime/librime librime1
cd librime1
make
cd build/bin
./rime_api_console
{F4}                                      # this shows that full_shape is currently off
2
3                                         # this toggles full_shape through options menu
{F4}                                      # this shows that full_shape is currently on
exit
cat user.yaml                             # this shows that full_shape is currently on
./rime_api_console
{F4}                                      # this shows that full_shape is currently on

session 2

git clone https://github.com/rime/librime librime2
cd librime2
make
cd build/bin
./rime_api_console
{F4}                                      # this shows that full_shape is currently off
{Escape}
{Control+Shift+3}                         # this toggles full_shape through keyboard shortcut
{F4}                                      # this shows that full_shape is currently on
exit
cat user.yaml                             # this shows that full_shape is currently off!!!
./rime_api_console
{F4}                                      # this shows that full_shape is currently off!!!

Expected behavior On every platform, in session 2, on lines marked with !!!, the option should show as having been toggled, or on.

Flavor(please complete the following information): Select your flavor:

  • [ ] ibus-rime
  • [ ] fcitx-rime
  • [ ] fcitx5-rime
  • [ ] Squirrel
  • [ ] Trime
  • [x] Weasel

Package:

  • OS: Microsoft Windows 10 Home 10.0.19045 Build 19045
  • Version: 0.15.0
  • URI: https://github.com/rime/weasel/releases/download/0.15.0/weasel-0.15.0.0-installer.exe

Additional context I have been able to fix the bug locally as follows: Comparing calls to Context::set_option in switch_translator.cc and key_binder.cc, those in switch_translator.cc are followed by a call to Config::SetBool whereas those in key_binder.cc are not. By adding similar statements to key_binder.cc, the bug is fixed. The logic needs to be fixed for all of radio_select_option, toggle_option, set_option, and unset_option; perhaps they can share a function which performs the persistence. I am unsure about how to contribute my fix to this project, but am happy to do so. Thank you!

russell-liu avatar Feb 15 '24 01:02 russell-liu

目前的策略就是這樣. 參考其他主流中文輸入法, 快捷鍵做臨時的狀態切換. 而方案選單類似設置程序的作用.

lotem avatar Mar 09 '24 03:03 lotem

不過這裏可能有 BUG: session 2 裏, 切換方案前後 full_shape 應當不變. 這不是通過保存到 user.yaml 實現的, 而是不清除或重置內存中的狀態. 除非方案裏指名要重置 (如 ascii_mode 通常在切換方案後重置爲 0).

lotem avatar Mar 09 '24 03:03 lotem

退出 rime_api_console 進程後再運行就不是同一個 session 了.

lotem avatar Mar 09 '24 03:03 lotem

Understood; thank you for your help. I guess the issue can be closed?

russell-liu avatar Mar 23 '24 22:03 russell-liu