Skip to content

Commit 416783a

Browse files
authored
Merge pull request #871 from lukhnos/fix-hsu-eten26-layout
Fix Hsu and ETen26 out-of-order sequence handling
2 parents 937d5dd + e3dab67 commit 416783a

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

Source/Engine/Mandarin/Mandarin.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ class BopomofoKeyboardLayout {
302302
syllable += head;
303303
} else if (syllable.maskType() < follow.maskType()) {
304304
syllable += follow;
305+
} else if ((syllable.maskType() == follow.maskType()) &&
306+
syllable.maskType() == BPMF::VowelMask) {
307+
// if the existing syllable contains only a vowel, and the
308+
// current character has 2+ possibilities, and the second (follow)
309+
// choice is also a vowel, we run into the case where the user
310+
// may have typed the consonant-vowel sequence in the wrong
311+
// order, and so the first (head) choice, which is always a
312+
// consonant, must be taken.
313+
syllable += head;
305314
} else {
306315
syllable += ending;
307316
}

Source/Engine/Mandarin/MandarinTest.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ TEST(MandarinTest, ETen26Layout) {
101101
ASSERT_EQ(buf.composedString(), "ㄗㄢˋ");
102102
}
103103

104+
TEST(MandarinTest, ETen26LayoutOutOfOrderEquivalentSequence) {
105+
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::ETen26Layout());
106+
buf.combineKey('q');
107+
buf.combineKey('a');
108+
ASSERT_EQ(buf.composedString(), "ㄗㄚ");
109+
110+
buf.clear();
111+
buf.combineKey('a'); // ㄚ first
112+
buf.combineKey('q'); // even if q can be ㄟ, a vowel is already in place
113+
ASSERT_EQ(buf.composedString(), "ㄗㄚ");
114+
115+
buf.clear();
116+
buf.combineKey('q');
117+
buf.combineKey('i');
118+
ASSERT_EQ(buf.composedString(), "ㄗㄞ");
119+
120+
buf.clear();
121+
buf.combineKey('i');
122+
buf.combineKey('q');
123+
ASSERT_EQ(buf.composedString(), "ㄗㄞ");
124+
}
104125
TEST(MandarinTest, HsuLayout) {
105126
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::HsuLayout());
106127
buf.combineKey('f');
@@ -109,6 +130,28 @@ TEST(MandarinTest, HsuLayout) {
109130
ASSERT_EQ(buf.composedString(), "ㄈㄟˇ");
110131
}
111132

133+
TEST(MandarinTest, HsuLayoutOutOfOrderEquivalentSequence) {
134+
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::HsuLayout());
135+
buf.combineKey('a');
136+
buf.combineKey('i');
137+
ASSERT_EQ(buf.composedString(), "ㄘㄞ");
138+
139+
buf.clear();
140+
buf.combineKey('i'); // ㄞ first
141+
buf.combineKey('a'); // even if a can be ㄟ, a vowel is already in place
142+
ASSERT_EQ(buf.composedString(), "ㄘㄞ");
143+
144+
buf.clear();
145+
buf.combineKey('a');
146+
buf.combineKey('y');
147+
ASSERT_EQ(buf.composedString(), "ㄘㄚ");
148+
149+
buf.clear();
150+
buf.combineKey('y');
151+
buf.combineKey('a');
152+
ASSERT_EQ(buf.composedString(), "ㄘㄚ");
153+
}
154+
112155
TEST(MandarinTest, IBMLayout) {
113156
BopomofoReadingBuffer buf(BopomofoKeyboardLayout::IBMLayout());
114157
buf.combineKey('9');

0 commit comments

Comments
 (0)