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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/rime/candidate.h
Expand Up @@ -88,16 +88,21 @@ 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 allow_erase_comment = false)
: Candidate(type, item->start(), item->end(), item->quality()),
text_(text), comment_(comment),
item_(item) {}
item_(item), allow_erase_comment_(allow_erase_comment) {}

const string& text() const {
return text_.empty() ? item_->text() : text_;
}
string comment() const {
return comment_.empty() ? item_->comment() : comment_;
if (allow_erase_comment_) {
LEOYoon-Tsaw marked this conversation as resolved.
Show resolved Hide resolved
return comment_;
} else {
return comment_.empty() ? item_->comment() : comment_;
}
}
string preedit() const {
return item_->preedit();
Expand All @@ -109,6 +114,7 @@ class ShadowCandidate : public Candidate {
string text_;
string comment_;
an<Candidate> item_;
bool allow_erase_comment_;
};

class UniquifiedCandidate : public Candidate {
Expand Down
4 changes: 3 additions & 1 deletion src/rime/gear/simplifier.cc
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_ + "/allow_erase_comment", &allow_erase_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,
allow_erase_comment_));
}

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