diff --git a/src/rime/gear/switch_translator.cc b/src/rime/gear/switch_translator.cc index ffaa3cfb4d..831a3cd454 100644 --- a/src/rime/gear/switch_translator.cc +++ b/src/rime/gear/switch_translator.cc @@ -30,6 +30,11 @@ inline static string get_state_label(const SwitchOption& option, Switches::GetStateLabel(option.the_switch, state_index, abbreviate)); } +inline static bool has_state_label(const SwitchOption& option, + size_t state_index) { + return bool(Switches::GetStateLabel(option.the_switch, state_index, false)); +} + class Switch : public SimpleCandidate, public SwitcherCommand { public: Switch(const SwitchOption& option, bool current_state, bool auto_save) @@ -208,6 +213,9 @@ void SwitchTranslation::LoadSwitches(Switcher* switcher) { switches.FindOption( [this, switcher, context, &groups](Switches::SwitchOption option) -> Switches::FindResult { + if (!has_state_label(option, 0)) { + return Switches::kContinue; + } if (option.type == Switches::kToggleOption) { bool current_state = context->get_option(option.option_name); Append(New(option, current_state, @@ -234,9 +242,11 @@ void SwitchTranslation::LoadSwitches(Switcher* switcher) { Switches::SwitchOption option) -> Switches::FindResult { bool current_state = context->get_option(option.option_name); if (option.type == Switches::kToggleOption) { - folded_options->Append(option, current_state); + if (has_state_label(option, current_state)) { + folded_options->Append(option, current_state); + } } else if (option.type == Switches::kRadioGroup) { - if (current_state) { + if (current_state && has_state_label(option, option.option_index)) { folded_options->Append(option, option.option_index); } } diff --git a/src/rime/switches.h b/src/rime/switches.h index cbe424b6fb..b2de5fcfa8 100644 --- a/src/rime/switches.h +++ b/src/rime/switches.h @@ -17,6 +17,8 @@ struct StringSlice { operator string() const { return str && length ? string(str, length) : string(); } + + operator bool() const { return bool(str) && bool(length); } }; class Switches {