Skip to content

Commit

Permalink
Try to use set comment wherever possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Apr 14, 2024
1 parent af4a883 commit e7d0923
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
16 changes: 6 additions & 10 deletions im/pinyin/pinyin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ class StrokeCandidateWord : public CandidateWord,
const std::string &py, int order)
: PinyinAbstractExtraCandidateWordInterface(*this, order),
engine_(engine), hz_(std::move(hz)) {
if (py.empty()) {
setText(Text(hz_));
} else {
setText(Text(fmt::format(_("{0} ({1})"), hz_, py)));
setText(Text(hz_));
if (!py.empty()) {
setComment(Text(py));
}
}

Expand Down Expand Up @@ -218,14 +217,11 @@ class PinyinPunctuationCandidateWord : public CandidateWord {
public:
PinyinPunctuationCandidateWord(const PinyinEngine *engine, std::string word,
bool isHalf)
: CandidateWord(), engine_(engine), word_(std::move(word)) {
Text text;
: engine_(engine), word_(std::move(word)) {
setText(Text(word_));
if (isHalf) {
text.append(fmt::format(_("{0} (Half)"), word_));
} else {
text.append(word_);
setComment(Text(_("(Half)")));
}
setText(std::move(text));
}

void select(InputContext *inputContext) const override {
Expand Down
19 changes: 8 additions & 11 deletions im/table/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ class TablePinyinCandidateWord : public CandidateWord {
const libime::TableBasedDictionary &dict,
bool customHint)
: engine_(engine), word_(std::move(word)) {
Text text;
text.append(word_);
setText(Text(word_));
if (utf8::lengthValidated(word_) == 1) {
if (auto code = dict.reverseLookup(word_); !code.empty()) {
text.append(" ~ ");
Text comment;
comment.append("~ ");
if (customHint) {
text.append(dict.hint(code));
comment.append(dict.hint(code));
} else {
text.append(std::move(code));
comment.append(std::move(code));
}
setComment(std::move(comment));
}
}
setText(std::move(text));
}

void select(InputContext *inputContext) const override {
Expand All @@ -112,13 +112,10 @@ class TablePunctuationCandidateWord : public CandidateWord {
TablePunctuationCandidateWord(TableState *state, std::string word,
bool isHalf)
: state_(state), word_(std::move(word)) {
Text text;
setText(Text(word_));
if (isHalf) {
text.append(fmt::format(_("{0} (Half)"), word_));
} else {
text.append(word_);
setComment(Text(_("(Half)")));
}
setText(std::move(text));
}

void select(InputContext *inputContext) const override {
Expand Down

0 comments on commit e7d0923

Please sign in to comment.