Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/Engine/Mandarin/Mandarin.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ class BopomofoReadingBuffer {

void setKeyboardLayout(const BopomofoKeyboardLayout* layout) {
layout_ = layout;
pinyin_mode_ = layout == BopomofoKeyboardLayout::HanyuPinyinLayout();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

When switching from a standard keyboard layout to the Hanyu Pinyin layout, pinyin_mode_ is set to true and pinyin_sequence_ is cleared to "". However, syllable_ is not cleared. This creates an inconsistent state where isEmpty() returns false (since syllable_ is not empty) but composedString() returns "" (since it returns pinyin_sequence_ when pinyin_mode_ is true).

Furthermore, any subsequent keypress or backspace will completely overwrite or clear the existing syllable without preserving the composition.

To maintain consistency and preserve the composition (similar to how it is preserved when switching from Hanyu Pinyin to a standard layout), pinyin_sequence_ should be populated from the existing syllable_ using syllable_.HanyuPinyinString(true, true).

Here is the recommended implementation:

  void setKeyboardLayout(const BopomofoKeyboardLayout* layout) {
    layout_ = layout;
    pinyin_mode_ = layout == BopomofoKeyboardLayout::HanyuPinyinLayout();

    if (pinyin_mode_) {
      pinyin_sequence_ = syllable_.HanyuPinyinString(true, true);
    }
  }
  void setKeyboardLayout(const BopomofoKeyboardLayout* layout) {
    layout_ = layout;
    pinyin_mode_ = layout == BopomofoKeyboardLayout::HanyuPinyinLayout();

    if (pinyin_mode_) {
      pinyin_sequence_ = syllable_.HanyuPinyinString(true, true);
    }
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The HanyuPinyinString section doesn’t make any sense to me...


if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) {
pinyin_mode_ = true;
if (pinyin_mode_) {
pinyin_sequence_ = "";
}
}
Expand Down
Loading