Skip to content

Commit

Permalink
feat(punctuator): option convert_digit_separators
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Jan 17, 2025
1 parent 14ccab0 commit 2c3bc4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/rime/gear/punctuator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ an<ConfigItem> PunctConfig::GetPunctDefinition(const string key) {
Punctuator::Punctuator(const Ticket& ticket) : Processor(ticket) {
Config* config = engine_->schema()->config();
if (config) {
config->GetBool("punctuator/convert_digit_separators", &convert_digit_separators_);
config->GetBool("punctuator/use_space", &use_space_);
}
config_.LoadConfig(engine_);
Expand Down Expand Up @@ -97,7 +98,7 @@ ProcessResult Punctuator::ProcessKeyEvent(const KeyEvent& key_event) {
if (!use_space_ && ch == XK_space && ctx->IsComposing()) {
return kNoop;
}
if (isdigit(ch) && is_after_digit_separator(ctx)) {
if (convert_digit_separators_ && isdigit(ch) && is_after_digit_separator(ctx)) {
ctx->PushInput(ch) && ctx->Commit();
return kAccepted;
}
Expand All @@ -121,6 +122,9 @@ ProcessResult Punctuator::ProcessKeyEvent(const KeyEvent& key_event) {
}

bool Punctuator::ToggleNumberMode(char ch) {
if (!convert_digit_separators_) {
return false;
}
Context* ctx = engine_->context();
Composition& comp = ctx->composition();
if (comp.empty()) {
Expand Down Expand Up @@ -207,6 +211,10 @@ bool Punctuator::PairPunct(const an<ConfigItem>& definition) {
}

PunctSegmentor::PunctSegmentor(const Ticket& ticket) : Segmentor(ticket) {
Config* config = engine_->schema()->config();
if (config) {
config->GetBool("punctuator/convert_digit_separators", &convert_digit_separators_);
}
config_.LoadConfig(engine_);
}

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 @@ -43,6 +43,7 @@ class Punctuator : public Processor {
bool PairPunct(const an<ConfigItem>& definition);

PunctConfig config_;
bool convert_digit_separators_ = true;
bool use_space_ = false;
map<an<ConfigItem>, int> oddness_;
};
Expand All @@ -54,6 +55,7 @@ class PunctSegmentor : public Segmentor {

protected:
PunctConfig config_;
bool convert_digit_separators_ = true;
};

class PunctTranslator : public Translator {
Expand Down

0 comments on commit 2c3bc4a

Please sign in to comment.