Add support for boolean options
This commit is contained in:
parent
fac222a427
commit
09cf5acb23
|
@ -377,7 +377,7 @@ public:
|
|||
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
|
||||
context().ui().menu_show(candidates, menu_pos, MenuStyle::Prompt);
|
||||
|
||||
bool use_common_prefix = context().options()["complete_prefix"].get<int>();
|
||||
bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
|
||||
String prefix = use_common_prefix ? common_prefix(candidates) : String();
|
||||
if (m_completions.end - m_completions.start > prefix.length())
|
||||
prefix = line.substr(m_completions.start,
|
||||
|
|
|
@ -176,7 +176,7 @@ void do_search(Context& context)
|
|||
RegisterManager::instance()['/'] = ex;
|
||||
context.push_jump();
|
||||
}
|
||||
else if (ex.empty() or not context.options()["incsearch"].get<int>())
|
||||
else if (ex.empty() or not context.options()["incsearch"].get<bool>())
|
||||
return;
|
||||
|
||||
context.editor().select(std::bind(select_next_match<forward>, _1, ex), mode);
|
||||
|
|
|
@ -54,6 +54,21 @@ template class TypedOption<int>;
|
|||
template const int& Option::get<int>() const;
|
||||
template void Option::set<int>(const int&);
|
||||
|
||||
// TypedOption<bool> specializations;
|
||||
template<> String TypedOption<bool>::get_as_string() const { return m_value ? "true" : "false"; }
|
||||
template<> void TypedOption<bool>::set_from_string(const String& str)
|
||||
{
|
||||
if (str == "true" or str == "yes")
|
||||
m_value = true;
|
||||
else if (str == "false" or str == "no")
|
||||
m_value = false;
|
||||
else
|
||||
throw runtime_error("boolean values are either true, yes, false or no");
|
||||
}
|
||||
template class TypedOption<bool>;
|
||||
template const bool& Option::get<bool>() const;
|
||||
template void Option::set<bool>(const bool&);
|
||||
|
||||
OptionManager::OptionManager(OptionManager& parent)
|
||||
: m_parent(&parent)
|
||||
{
|
||||
|
@ -164,8 +179,8 @@ GlobalOptions::GlobalOptions()
|
|||
declare_option<String>("eolformat", "lf");
|
||||
declare_option<String>("BOM", "no");
|
||||
declare_option<String>("shell", "sh");
|
||||
declare_option<int>("complete_prefix", 1);
|
||||
declare_option<int>("incsearch", 1);
|
||||
declare_option<bool>("complete_prefix", true);
|
||||
declare_option<bool>("incsearch", true);
|
||||
declare_option<String>("ignored_files", R"(^(\..*|.*\.(o|so|a)))$)");
|
||||
declare_option<String>("filetype", "");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user