Skip to content

Commit

Permalink
Merge pull request #441 from mlouielu/fix-pinyin-condition
Browse files Browse the repository at this point in the history
fix: pinyin keyboard detection should not depend on enum ordering
  • Loading branch information
kanru authored Feb 25, 2024
2 parents b026533 + fc45e25 commit 1711d4e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/internal/bopomofo-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int BopomofoKeyseq(BopomofoData *, char key_seq[10]);
int BopomofoSyllableIndex(BopomofoData *);
int BopomofoSyllableIndexAlt(BopomofoData *);
int BopomofoKbType(BopomofoData *);
int BopomofoKbIsPinyin(BopomofoData *);

/* *INDENT-OFF* */
#endif
Expand Down
18 changes: 15 additions & 3 deletions src/bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ int BopomofoRemoveLast(BopomofoData *pBopomofo)
{
int i;

if (pBopomofo->kbtype >= KB_HANYU_PINYIN) {
if (BopomofoKbIsPinyin(pBopomofo)) {
i = strlen(pBopomofo->pinYinData.keySeq);
pBopomofo->pinYinData.keySeq[i - 1] = '\0';
} else {
Expand All @@ -690,7 +690,7 @@ int BopomofoIsEntering(BopomofoData *pBopomofo)
{
int i;

if (pBopomofo->kbtype >= KB_HANYU_PINYIN) {
if (BopomofoKbIsPinyin(pBopomofo)) {
if (pBopomofo->pinYinData.keySeq[0])
return 1;
} else {
Expand Down Expand Up @@ -720,4 +720,16 @@ int BopomofoSyllableIndexAlt(BopomofoData *pBopomofo)
int BopomofoKbType(BopomofoData *pBopomofo)
{
return pBopomofo->kbtype;
}
}

int BopomofoKbIsPinyin(BopomofoData *pBopomofo)
{
switch (BopomofoKbType(pBopomofo)) {
case KB_HANYU_PINYIN:
case KB_THL_PINYIN:
case KB_MPS2_PINYIN:
return 1;
default:
return 0;
}
}
2 changes: 1 addition & 1 deletion src/chewingutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ int MakeOutput(ChewingOutput *pgo, ChewingData *pgdata)
pgo->chiSymbolCursor = pgdata->chiSymbolCursor;

/* fill bopomofoBuf */
if (BopomofoKbType(&pgdata->bopomofoData) >= KB_HANYU_PINYIN) {
if (BopomofoKbIsPinyin(&pgdata->bopomofoData)) {
char key_seq[10];
BopomofoKeyseq(&pgdata->bopomofoData, key_seq);
strcpy(pgo->bopomofoBuf, key_seq);
Expand Down

0 comments on commit 1711d4e

Please sign in to comment.