Skip to content

Commit f81c971

Browse files
committed
fix(switcher): deactivate before setting option
Fixes #918
1 parent f6dd300 commit f81c971

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

src/rime/gear/schema_list_translator.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ class SchemaSelection : public SimpleCandidate, public SwitcherCommand {
2525
};
2626

2727
void SchemaSelection::Apply(Switcher* switcher) {
28-
switcher->Deactivate();
29-
if (Engine* engine = switcher->attached_engine()) {
30-
if (keyword_ != engine->schema()->schema_id()) {
31-
engine->ApplySchema(new Schema(keyword_));
28+
switcher->DeactivateAndApply([this, switcher] {
29+
if (Engine* engine = switcher->attached_engine()) {
30+
if (keyword_ != engine->schema()->schema_id()) {
31+
engine->ApplySchema(new Schema(keyword_));
32+
}
3233
}
33-
}
34+
});
3435
}
3536

3637
class SchemaAction : public ShadowCandidate, public SwitcherCommand {

src/rime/gear/switch_translator.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ class Switch : public SimpleCandidate, public SwitcherCommand {
5555
};
5656

5757
void Switch::Apply(Switcher* switcher) {
58-
if (Engine* engine = switcher->attached_engine()) {
59-
engine->context()->set_option(keyword_, target_state_);
60-
}
61-
if (auto_save_) {
62-
if (Config* user_config = switcher->user_config()) {
63-
user_config->SetBool("var/option/" + keyword_, target_state_);
58+
switcher->DeactivateAndApply([this, switcher] {
59+
if (Engine* engine = switcher->attached_engine()) {
60+
engine->context()->set_option(keyword_, target_state_);
6461
}
65-
}
66-
switcher->Deactivate();
62+
if (auto_save_) {
63+
if (Config* user_config = switcher->user_config()) {
64+
user_config->SetBool("var/option/" + keyword_, target_state_);
65+
}
66+
}
67+
});
6768
}
6869

6970
class RadioOption;
@@ -100,8 +101,7 @@ class RadioOption : public SimpleCandidate, public SwitcherCommand {
100101
};
101102

102103
void RadioOption::Apply(Switcher* switcher) {
103-
group_->SelectOption(this);
104-
switcher->Deactivate();
104+
switcher->DeactivateAndApply([this] { group_->SelectOption(this); });
105105
}
106106

107107
void RadioOption::UpdateState(bool selected) {

src/rime/switcher.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,16 @@ void Switcher::Activate() {
249249
}
250250

251251
void Switcher::Deactivate() {
252-
context_->Clear();
252+
active_ = false;
253253
engine_->set_active_engine();
254+
context_->Clear();
255+
}
256+
257+
void Switcher::DeactivateAndApply(function<void()> apply) {
254258
active_ = false;
259+
engine_->set_active_engine();
260+
apply();
261+
context_->Clear();
255262
}
256263

257264
void Switcher::LoadSettings() {

src/rime/switcher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Switcher : public Processor, public Engine {
4040
void RefreshMenu();
4141
void Activate();
4242
void Deactivate();
43+
void DeactivateAndApply(function<void()> apply);
4344

4445
Engine* attached_engine() const { return engine_; }
4546
Config* user_config() const { return user_config_.get(); }

0 commit comments

Comments
 (0)