Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow simplifier to return empty comment #541

Merged
merged 5 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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