Skip to content

Commit

Permalink
Add show_full_code Option for Table Translator
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Nov 14, 2023
1 parent b30fa28 commit d8667c9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/rime/gear/table_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ an<Candidate> TableTranslation::Peek() {
return nullptr;
bool is_user_phrase = PreferUserPhrase();
auto e = PreferredEntry(is_user_phrase);
string comment(is_constructed(e.get()) ? kUnitySymbol : e->comment);
string comment(e->comment);
if (is_constructed(e.get())) {
comment = kUnitySymbol;
} else if (options_ && options_->show_full_code())
if (auto translator = dynamic_cast<TableTranslator*>(options_)) {
comment = translator->Spell(e->code);
}
if (options_) {
options_->comment_formatter().Apply(&comment);
}
Expand Down Expand Up @@ -354,6 +360,16 @@ bool TableTranslator::Memorize(const CommitEntry& commit_entry) {
return true;
}

string TableTranslator::Spell(const Code& code) {
string result;
vector<string> syllables;
if (!dict_ || !dict_->Decode(code, &syllables) || syllables.empty())
return result;
result = boost::algorithm::join(syllables, string(1, delimiters_.at(0)));
// comment_formatter_.Apply(&result); // Done in TableTranslation::Peek()
return result;
}

string TableTranslator::GetPrecedingText(size_t start) const {
return !contextual_suggestions_ ? string()
: start > 0 ? engine_->context()->composition().GetTextBefore(start)
Expand Down
1 change: 1 addition & 0 deletions src/rime/gear/table_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TableTranslator : public Translator,
size_t start,
bool include_prefix_phrases = false);
string GetPrecedingText(size_t start) const;
string Spell(const Code& code);
UnityTableEncoder* encoder() const { return encoder_.get(); }

protected:
Expand Down
1 change: 1 addition & 0 deletions src/rime/gear/translator_commons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ TranslatorOptions::TranslatorOptions(const Ticket& ticket) {
config->GetBool(ticket.name_space + "/enable_completion",
&enable_completion_);
config->GetBool(ticket.name_space + "/strict_spelling", &strict_spelling_);
config->GetBool(ticket.name_space + "/show_full_code", &show_full_code_);
config->GetDouble(ticket.name_space + "/initial_quality",
&initial_quality_);
preedit_formatter_.Load(
Expand Down
4 changes: 4 additions & 0 deletions src/rime/gear/translator_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct Ticket;
class TranslatorOptions {
public:
TranslatorOptions(const Ticket& ticket);
virtual ~TranslatorOptions() {}
bool IsUserDictDisabledFor(const string& input) const;

const string& delimiters() const { return delimiters_; }
Expand All @@ -154,6 +155,8 @@ class TranslatorOptions {
void set_enable_completion(bool enabled) { enable_completion_ = enabled; }
bool strict_spelling() const { return strict_spelling_; }
void set_strict_spelling(bool is_strict) { strict_spelling_ = is_strict; }
bool show_full_code() const { return show_full_code_; }
void set_show_full_code(bool enabled) { show_full_code_ = enabled; }
double initial_quality() const { return initial_quality_; }
void set_initial_quality(double quality) { initial_quality_ = quality; }
Projection& preedit_formatter() { return preedit_formatter_; }
Expand All @@ -165,6 +168,7 @@ class TranslatorOptions {
bool contextual_suggestions_ = false;
bool enable_completion_ = true;
bool strict_spelling_ = false;
bool show_full_code_ = false;
double initial_quality_ = 0.;
Projection preedit_formatter_;
Projection comment_formatter_;
Expand Down

0 comments on commit d8667c9

Please sign in to comment.