Skip to content

Commit

Permalink
feat: add append_comment option to reverse_lookup_filter (rime#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 and groverlynn committed Sep 27, 2023
1 parent 194b4dd commit a71a8f6
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
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
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 a71a8f6

Please sign in to comment.