Skip to content

Commit

Permalink
feat(punctuator): add option to commit digit separator (#981)
Browse files Browse the repository at this point in the history
follow-up #972
instead of converting it to a `punct_number` segment in the input
buffer, this option reproduces the behaviour before commit e02d6b3.

opt in with `punctuator/digit_separator_action: commit`
  • Loading branch information
lotem authored Feb 15, 2025
1 parent 63a6d1b commit 4b90ff1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/rime/gear/punctuator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void PunctConfig::LoadConfig(Engine* engine, bool load_symbols) {
digit_separators_ = configured;
}
}
{
string configured;
if (config->GetString("punctuator/digit_separator_action", &configured)) {
digit_separator_commit_ = (configured == "commit");
}
}
}

an<ConfigItem> PunctConfig::GetPunctDefinition(const string key) {
Expand Down Expand Up @@ -133,7 +139,8 @@ bool Punctuator::ConvertDigitSeparator(char ch) {
if (ctx->composition().empty() && is_after_number(ctx)) {
DLOG(INFO) << "convert punct in number: " << ch;
ctx->PushInput(ch) && punctuation_is_translated(ctx, "punct_number") &&
ctx->composition().Forward();
(config_.digit_separator_commit() ? ctx->Commit()
: ctx->composition().Forward());
return true;
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/rime/gear/punctuator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class PunctConfig {
bool is_digit_separator(char ch) const {
return digit_separators_.find(ch) != string::npos;
}
bool digit_separator_commit() const { return digit_separator_commit_; }

protected:
string shape_;
an<ConfigMap> mapping_;
an<ConfigMap> symbols_;

string digit_separators_ = ",.:'";
bool digit_separator_commit_ = false;
};

class Punctuator : public Processor {
Expand Down

0 comments on commit 4b90ff1

Please sign in to comment.