diff --git a/src/rime/engine.cc b/src/rime/engine.cc index 76ef73ff51..3ccc374e9a 100644 --- a/src/rime/engine.cc +++ b/src/rime/engine.cc @@ -52,6 +52,9 @@ class ConcreteEngine : public Engine { vector> filters_; vector> formatters_; vector> post_processors_; + // To make sure dumping user.yaml when processors_.clear(), + // switcher is owned by processors_[0] + weak switcher_; }; // implementations @@ -274,6 +277,14 @@ void ConcreteEngine::OnSelect(Context* ctx) { void ConcreteEngine::ApplySchema(Schema* schema) { if (!schema) return; + if (auto switcher = switcher_.lock()) { + if (Config* user_config = switcher->user_config()) { + user_config->SetString("var/previously_selected_schema", + schema->schema_id()); + user_config->SetInt("var/schema_access_time/" + schema->schema_id(), + time(NULL)); + } + } schema_.reset(schema); context_->Clear(); context_->ClearTransientOptions(); @@ -289,6 +300,7 @@ void ConcreteEngine::InitializeComponents() { filters_.clear(); if (auto switcher = New(this)) { + switcher_ = switcher; processors_.push_back(switcher); if (schema_->schema_id() == ".default") { if (Schema* schema = switcher->CreateSchema()) { diff --git a/src/rime/gear/schema_list_translator.cc b/src/rime/gear/schema_list_translator.cc index 4a9b6138b0..e31dfaf1d8 100644 --- a/src/rime/gear/schema_list_translator.cc +++ b/src/rime/gear/schema_list_translator.cc @@ -26,10 +26,6 @@ class SchemaSelection : public SimpleCandidate, public SwitcherCommand { void SchemaSelection::Apply(Switcher* switcher) { switcher->Deactivate(); - if (Config* user_config = switcher->user_config()) { - user_config->SetString("var/previously_selected_schema", keyword_); - user_config->SetInt("var/schema_access_time/" + keyword_, time(NULL)); - } if (Engine* engine = switcher->attached_engine()) { if (keyword_ != engine->schema()->schema_id()) { engine->ApplySchema(new Schema(keyword_));