Use common completion system for OptionManager::complete_option_name
This commit is contained in:
parent
013519b3cb
commit
e784db4ad6
|
@ -112,31 +112,15 @@ void OptionManager::on_option_changed(const Option& option)
|
||||||
watcher->on_option_changed(option);
|
watcher->on_option_changed(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container, typename MatchingFunc>
|
|
||||||
static CandidateList get_matching_names(const Container& options, MatchingFunc func)
|
|
||||||
{
|
|
||||||
CandidateList result;
|
|
||||||
for (auto& option : options)
|
|
||||||
{
|
|
||||||
if (option->flags() & OptionFlags::Hidden)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const auto& name = option->name();
|
|
||||||
if (func(name))
|
|
||||||
result.push_back(name);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
CandidateList OptionsRegistry::complete_option_name(StringView prefix,
|
CandidateList OptionsRegistry::complete_option_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const
|
ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using OptionPtr = std::unique_ptr<OptionDesc>;
|
||||||
auto real_prefix = prefix.substr(0, cursor_pos);
|
return complete(prefix, cursor_pos, m_descs |
|
||||||
auto result = get_matching_names(m_descs, std::bind(prefix_match, _1, real_prefix));
|
filter([](const OptionPtr& desc)
|
||||||
if (result.empty())
|
{ return not (desc->flags() & OptionFlags::Hidden); }) |
|
||||||
result = get_matching_names(m_descs, std::bind(subsequence_match, _1, real_prefix));
|
transform([](const OptionPtr& desc) -> const String&
|
||||||
return result;
|
{ return desc->name(); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user