Skip to content

Commit 4b90ff1

Browse files
authored
feat(punctuator): add option to commit digit separator (#981)
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`
1 parent 63a6d1b commit 4b90ff1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/rime/gear/punctuator.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ void PunctConfig::LoadConfig(Engine* engine, bool load_symbols) {
4040
digit_separators_ = configured;
4141
}
4242
}
43+
{
44+
string configured;
45+
if (config->GetString("punctuator/digit_separator_action", &configured)) {
46+
digit_separator_commit_ = (configured == "commit");
47+
}
48+
}
4349
}
4450

4551
an<ConfigItem> PunctConfig::GetPunctDefinition(const string key) {
@@ -133,7 +139,8 @@ bool Punctuator::ConvertDigitSeparator(char ch) {
133139
if (ctx->composition().empty() && is_after_number(ctx)) {
134140
DLOG(INFO) << "convert punct in number: " << ch;
135141
ctx->PushInput(ch) && punctuation_is_translated(ctx, "punct_number") &&
136-
ctx->composition().Forward();
142+
(config_.digit_separator_commit() ? ctx->Commit()
143+
: ctx->composition().Forward());
137144
return true;
138145
}
139146
return false;

src/rime/gear/punctuator.h

+2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ class PunctConfig {
2828
bool is_digit_separator(char ch) const {
2929
return digit_separators_.find(ch) != string::npos;
3030
}
31+
bool digit_separator_commit() const { return digit_separator_commit_; }
3132

3233
protected:
3334
string shape_;
3435
an<ConfigMap> mapping_;
3536
an<ConfigMap> symbols_;
3637

3738
string digit_separators_ = ",.:'";
39+
bool digit_separator_commit_ = false;
3840
};
3941

4042
class Punctuator : public Processor {

0 commit comments

Comments
 (0)