Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(punctuator): option to commit digit separator #981

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading