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

fix(switcher): deactivate before setting option #920

Merged
merged 1 commit into from
Jul 20, 2024
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
11 changes: 6 additions & 5 deletions src/rime/gear/schema_list_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class SchemaSelection : public SimpleCandidate, public SwitcherCommand {
};

void SchemaSelection::Apply(Switcher* switcher) {
switcher->Deactivate();
if (Engine* engine = switcher->attached_engine()) {
if (keyword_ != engine->schema()->schema_id()) {
engine->ApplySchema(new Schema(keyword_));
switcher->DeactivateAndApply([this, switcher] {
if (Engine* engine = switcher->attached_engine()) {
if (keyword_ != engine->schema()->schema_id()) {
engine->ApplySchema(new Schema(keyword_));
}
}
}
});
}

class SchemaAction : public ShadowCandidate, public SwitcherCommand {
Expand Down
20 changes: 10 additions & 10 deletions src/rime/gear/switch_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ class Switch : public SimpleCandidate, public SwitcherCommand {
};

void Switch::Apply(Switcher* switcher) {
if (Engine* engine = switcher->attached_engine()) {
engine->context()->set_option(keyword_, target_state_);
}
if (auto_save_) {
if (Config* user_config = switcher->user_config()) {
user_config->SetBool("var/option/" + keyword_, target_state_);
switcher->DeactivateAndApply([this, switcher] {
if (Engine* engine = switcher->attached_engine()) {
engine->context()->set_option(keyword_, target_state_);
}
}
switcher->Deactivate();
if (auto_save_) {
if (Config* user_config = switcher->user_config()) {
user_config->SetBool("var/option/" + keyword_, target_state_);
}
}
});
}

class RadioOption;
Expand Down Expand Up @@ -100,8 +101,7 @@ class RadioOption : public SimpleCandidate, public SwitcherCommand {
};

void RadioOption::Apply(Switcher* switcher) {
group_->SelectOption(this);
switcher->Deactivate();
switcher->DeactivateAndApply([this] { group_->SelectOption(this); });
}

void RadioOption::UpdateState(bool selected) {
Expand Down
9 changes: 8 additions & 1 deletion src/rime/switcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,16 @@ void Switcher::Activate() {
}

void Switcher::Deactivate() {
context_->Clear();
active_ = false;
engine_->set_active_engine();
context_->Clear();
}

void Switcher::DeactivateAndApply(function<void()> apply) {
active_ = false;
engine_->set_active_engine();
apply();
context_->Clear();
}

void Switcher::LoadSettings() {
Expand Down
1 change: 1 addition & 0 deletions src/rime/switcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Switcher : public Processor, public Engine {
void RefreshMenu();
void Activate();
void Deactivate();
void DeactivateAndApply(function<void()> apply);

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