chewing / libchewing

libchewing - The intelligent phonetic input method library
https://chewing.im/
GNU Lesser General Public License v2.1
360 stars 90 forks source link

Home and End keys not working with the Rust version #527

Closed yan12125 closed 4 months ago

yan12125 commented 5 months ago

Describe the bug

When there are some texts in a text box, Home/End keys do not work when fcitx5-chewing is used with the Rust version of libchewing. With the C version (0.7.0), those keys work fine.

To Reproduce Steps to reproduce the behavior:

  1. Type some random characters (ex: 中文)
  2. Hit Home
  3. Use arrow keys to move cursor to the beginning of the text box
  4. Hit End

Expected behavior Home/End should move the cursor to beginning/end of the text box

Screenshots

Platform (please complete the following information):

Additional context

I haven't had time to analyze the issue yet. As the issue happens only with the Rust version, I assume this is a libchewing issue.

Here are logs with the 0.8.0 rc4, using the command RUST_LOG=debug fcitx5 -D --verbose chewing=5:

D2024-05-10 12:26:45.765502 eim.cpp:436] KeyEvent: Home
D2024-05-10 12:26:45.765609 eim.cpp:261] [src/editor/mod.rs:730 chewing::editor] process_keyevent: key-K58-Home-�-
D2024-05-10 12:26:45.765716 eim.cpp:261] [src/editor/mod.rs:749 chewing::editor] last_key_behavior = Absorb
D2024-05-10 12:26:45.765780 eim.cpp:261] [src/editor/mod.rs:750 chewing::editor] comp: CompositionEditor { cursor: 0, cursor_stack: [], inner: Composition { symbols: [], gaps: [], selections: [] } }
D2024-05-10 12:26:45.765838 eim.cpp:610] updateUI
D2024-05-10 12:26:45.765899 eim.cpp:562] Text:  Zuin:
D2024-05-10 12:26:50.573320 eim.cpp:436] KeyEvent: End
D2024-05-10 12:26:50.573464 eim.cpp:261] [src/editor/mod.rs:730 chewing::editor] process_keyevent: key-K59-End-�-
D2024-05-10 12:26:50.573525 eim.cpp:261] [src/editor/mod.rs:749 chewing::editor] last_key_behavior = Absorb
D2024-05-10 12:26:50.573577 eim.cpp:261] [src/editor/mod.rs:750 chewing::editor] comp: CompositionEditor { cursor: 0, cursor_stack: [], inner: Composition { symbols: [], gaps: [], selections: [] } }
D2024-05-10 12:26:50.573628 eim.cpp:610] updateUI
D2024-05-10 12:26:50.573695 eim.cpp:562] Text:  Zuin:

And logs with 0.7.0:

D2024-05-10 12:27:42.539654 eim.cpp:261] [/usr/src/debug/libchewing/libchewing-0.7.0/src/chewingio.c:696 chewing_set_easySymbolInput] API call: mode = 0
D2024-05-10 12:27:42.539749 eim.cpp:436] KeyEvent: Home
D2024-05-10 12:27:42.539842 eim.cpp:261] [/usr/src/debug/libchewing/libchewing-0.7.0/src/chewingio.c:1393 chewing_handle_Home] API call:
D2024-05-10 12:27:42.539920 eim.cpp:261] [/usr/src/debug/libchewing/libchewing-0.7.0/src/mod_aux.c:425 chewing_keystroke_CheckIgnore] API call:
D2024-05-10 12:27:48.386430 eim.cpp:261] [/usr/src/debug/libchewing/libchewing-0.7.0/src/chewingio.c:696 chewing_set_easySymbolInput] API call: mode = 0
D2024-05-10 12:27:48.386464 eim.cpp:436] KeyEvent: End
D2024-05-10 12:27:48.386488 eim.cpp:261] [/usr/src/debug/libchewing/libchewing-0.7.0/src/chewingio.c:1418 chewing_handle_End] API call:
D2024-05-10 12:27:48.386506 eim.cpp:261] [/usr/src/debug/libchewing/libchewing-0.7.0/src/mod_aux.c:425 chewing_keystroke_CheckIgnore] API call:
kanru commented 5 months ago

Do you mean if I hit the Home key twice in a row the second Home be ignored by chewing and move the textbox cursor to the beginning of the input area?

Some existing text 中文
                   ^  ^---- pre-edit cursor
                    `--- input area cursor

Type Home Home

Some existing text 中文
^---- cursor
yan12125 commented 5 months ago

Sorry if I was not clear. The issue happens when strings are already committed (not sure if this is the correct term). At this time, fcitx5-chewing logs show that both chewing_buffer_String_static and chewing_bopomofo_String_static return an empty string:

2024-05-10 14:30:44.334656 eim.cpp:562] Text:  Zuin:

Here are verbose steps to reproduce:

  1. Type some characters and hit Enter. Now the cursor is at the end of the input area:
    中文
    ^---- input area cursor
  2. Hit Home. I expect the cursor to move to the beginning of the input area:
    中文
    ^---- input area cursor

    While the cursor remains at the end of the input area

    中文
    ^---- input area cursor