From f079c3c5522acdcbdac7f01f449f57435df95a52 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Sun, 3 Sep 2023 00:23:29 +0800 Subject: [PATCH] feat: add `append_comment` option to `reverse_lookup_filter` (#699) Allow reverse_lookup_filter to append new codes to existing comments --- src/rime/gear/reverse_lookup_filter.cc | 9 +++++++-- src/rime/gear/reverse_lookup_filter.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rime/gear/reverse_lookup_filter.cc b/src/rime/gear/reverse_lookup_filter.cc index 796f552af..70b144d9b 100644 --- a/src/rime/gear/reverse_lookup_filter.cc +++ b/src/rime/gear/reverse_lookup_filter.cc @@ -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")); } } @@ -69,7 +70,7 @@ an ReverseLookupFilter::Apply(an translation, } void ReverseLookupFilter::Process(const an& cand) { - if (!overwrite_comment_ && !cand->comment().empty()) + if (!cand->comment().empty() && !(overwrite_comment_ || append_comment_)) return; auto phrase = As(Candidate::GetGenuineCandidate(cand)); if (!phrase) @@ -78,7 +79,11 @@ void ReverseLookupFilter::Process(const an& 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); + } } } } diff --git a/src/rime/gear/reverse_lookup_filter.h b/src/rime/gear/reverse_lookup_filter.h index e297ed5db..28aadb3c3 100644 --- a/src/rime/gear/reverse_lookup_filter.h +++ b/src/rime/gear/reverse_lookup_filter.h @@ -34,6 +34,7 @@ class ReverseLookupFilter : public Filter, TagMatching { the rev_dict_; // settings bool overwrite_comment_ = false; + bool append_comment_ = false; Projection comment_formatter_; };