Skip to content

Commit 2368034

Browse files
LEOYoon-Tsawlotem
andauthored
feat(simplifier): can be configured to return empty comment (#541)
Allow simplifier to return empty comment by setting `simplifier/inherit_comment: false` Co-authored-by: 居戎氏 <chen.sst@gmail.com>
1 parent c63ce22 commit 2368034

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/rime/candidate.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ class ShadowCandidate : public Candidate {
8888
ShadowCandidate(const an<Candidate>& item,
8989
const string& type,
9090
const string& text = string(),
91-
const string& comment = string())
91+
const string& comment = string(),
92+
const bool inherit_comment = true)
9293
: Candidate(type, item->start(), item->end(), item->quality()),
9394
text_(text), comment_(comment),
94-
item_(item) {}
95+
item_(item), inherit_comment_(inherit_comment) {}
9596

9697
const string& text() const {
9798
return text_.empty() ? item_->text() : text_;
9899
}
99100
string comment() const {
100-
return comment_.empty() ? item_->comment() : comment_;
101+
return inherit_comment_ && comment_.empty() ? item_->comment() : comment_;
101102
}
102103
string preedit() const {
103104
return item_->preedit();
@@ -109,6 +110,7 @@ class ShadowCandidate : public Candidate {
109110
string text_;
110111
string comment_;
111112
an<Candidate> item_;
113+
bool inherit_comment_;
112114
};
113115

114116
class UniquifiedCandidate : public Candidate {

src/rime/gear/simplifier.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Simplifier::Simplifier(const Ticket& ticket) : Filter(ticket),
108108
(tips == "char") ? kTipsChar : kTipsNone;
109109
}
110110
config->GetBool(name_space_ + "/show_in_comment", &show_in_comment_);
111+
config->GetBool(name_space_ + "/inherit_comment", &inherit_comment_);
111112
comment_formatter_.Load(config->GetList(name_space_ + "/comment_format"));
112113
config->GetBool(name_space_ + "/random", &random_);
113114
config->GetString(name_space_ + "/option_name", &option_name_);
@@ -225,7 +226,8 @@ void Simplifier::PushBack(const an<Candidate>& original,
225226
original,
226227
"simplified",
227228
text,
228-
tips));
229+
tips,
230+
inherit_comment_));
229231
}
230232

231233
bool Simplifier::Convert(const an<Candidate>& original,

src/rime/gear/simplifier.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Simplifier : public Filter, TagMatching {
4646
string opencc_config_;
4747
set<string> excluded_types_;
4848
bool show_in_comment_ = false;
49+
bool inherit_comment_ = true;
4950
Projection comment_formatter_;
5051
bool random_ = false;
5152
};

0 commit comments

Comments
 (0)