Skip to content

Commit

Permalink
feat: add append_comment option to reverse_lookup_filter (#699)
Browse files Browse the repository at this point in the history
Allow reverse_lookup_filter to append new codes to existing comments
  • Loading branch information
ksqsf authored Sep 2, 2023
1 parent 8432190 commit f079c3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/rime/gear/reverse_lookup_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void ReverseLookupFilter::Initialize() {
}
if (Config* config = engine_->schema()->config()) {
config->GetBool(name_space_ + "/overwrite_comment", &overwrite_comment_);
config->GetBool(name_space_ + "/append_comment", &append_comment_);
comment_formatter_.Load(config->GetList(name_space_ + "/comment_format"));
}
}
Expand All @@ -69,7 +70,7 @@ an<Translation> ReverseLookupFilter::Apply(an<Translation> translation,
}

void ReverseLookupFilter::Process(const an<Candidate>& cand) {
if (!overwrite_comment_ && !cand->comment().empty())
if (!cand->comment().empty() && !(overwrite_comment_ || append_comment_))
return;
auto phrase = As<Phrase>(Candidate::GetGenuineCandidate(cand));
if (!phrase)
Expand All @@ -78,7 +79,11 @@ void ReverseLookupFilter::Process(const an<Candidate>& cand) {
if (rev_dict_->ReverseLookup(phrase->text(), &codes)) {
comment_formatter_.Apply(&codes);
if (!codes.empty()) {
phrase->set_comment(codes);
if (overwrite_comment_) {
phrase->set_comment(codes);
} else if (append_comment_) {
phrase->set_comment(cand->comment() + " " + codes);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rime/gear/reverse_lookup_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ReverseLookupFilter : public Filter, TagMatching {
the<ReverseLookupDictionary> rev_dict_;
// settings
bool overwrite_comment_ = false;
bool append_comment_ = false;
Projection comment_formatter_;
};

Expand Down

0 comments on commit f079c3c

Please sign in to comment.