Skip to content

Commit

Permalink
feat(simplifier): can be configured to return empty comment (#541)
Browse files Browse the repository at this point in the history
Allow simplifier to return empty comment by setting `simplifier/inherit_comment: false`

Co-authored-by: 居戎氏 <[email protected]>
  • Loading branch information
LEOYoon-Tsaw and lotem committed Jun 7, 2022
1 parent c63ce22 commit 2368034
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/rime/candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ class ShadowCandidate : public Candidate {
ShadowCandidate(const an<Candidate>& item,
const string& type,
const string& text = string(),
const string& comment = string())
const string& comment = string(),
const bool inherit_comment = true)
: Candidate(type, item->start(), item->end(), item->quality()),
text_(text), comment_(comment),
item_(item) {}
item_(item), inherit_comment_(inherit_comment) {}

const string& text() const {
return text_.empty() ? item_->text() : text_;
}
string comment() const {
return comment_.empty() ? item_->comment() : comment_;
return inherit_comment_ && comment_.empty() ? item_->comment() : comment_;
}
string preedit() const {
return item_->preedit();
Expand All @@ -109,6 +110,7 @@ class ShadowCandidate : public Candidate {
string text_;
string comment_;
an<Candidate> item_;
bool inherit_comment_;
};

class UniquifiedCandidate : public Candidate {
Expand Down
4 changes: 3 additions & 1 deletion src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Simplifier::Simplifier(const Ticket& ticket) : Filter(ticket),
(tips == "char") ? kTipsChar : kTipsNone;
}
config->GetBool(name_space_ + "/show_in_comment", &show_in_comment_);
config->GetBool(name_space_ + "/inherit_comment", &inherit_comment_);
comment_formatter_.Load(config->GetList(name_space_ + "/comment_format"));
config->GetBool(name_space_ + "/random", &random_);
config->GetString(name_space_ + "/option_name", &option_name_);
Expand Down Expand Up @@ -225,7 +226,8 @@ void Simplifier::PushBack(const an<Candidate>& original,
original,
"simplified",
text,
tips));
tips,
inherit_comment_));
}

bool Simplifier::Convert(const an<Candidate>& original,
Expand Down
1 change: 1 addition & 0 deletions src/rime/gear/simplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Simplifier : public Filter, TagMatching {
string opencc_config_;
set<string> excluded_types_;
bool show_in_comment_ = false;
bool inherit_comment_ = true;
Projection comment_formatter_;
bool random_ = false;
};
Expand Down

0 comments on commit 2368034

Please sign in to comment.