HighlighterGroup: use idvaluemap::complete_id_if in complete_group_id

This commit is contained in:
Maxime Coste 2012-01-19 20:53:15 +00:00
parent ce6b4c2cc4
commit bb36271ae5
2 changed files with 10 additions and 12 deletions

View File

@ -44,4 +44,13 @@ CandidateList HighlighterGroup::complete_id(const std::string& prefix,
return m_highlighters.complete_id<str_to_str>(prefix, cursor_pos); return m_highlighters.complete_id<str_to_str>(prefix, cursor_pos);
} }
CandidateList HighlighterGroup::complete_group_id(const std::string& prefix,
size_t cursor_pos)
{
return m_highlighters.complete_id_if<str_to_str>(
prefix, cursor_pos,
[](std::pair<std::string, HighlighterFunc>& func)
{ return func.second.target<HighlighterGroup>() != nullptr; });
}
} }

View File

@ -21,18 +21,7 @@ public:
HighlighterGroup& get_group(const std::string& id); HighlighterGroup& get_group(const std::string& id);
CandidateList complete_id(const std::string& prefix, size_t cursor_pos); CandidateList complete_id(const std::string& prefix, size_t cursor_pos);
CandidateList complete_group_id(const std::string& prefix, size_t cursor_pos);
CandidateList complete_group_id(const std::string& prefix, size_t cursor_pos)
{
CandidateList all = complete_id(prefix, cursor_pos);
CandidateList res;
for (auto& id : all)
{
if (m_highlighters.find(id)->second.target<HighlighterGroup>())
res.push_back(id);
}
return res;
}
private: private:
idvaluemap<std::string, HighlighterFunc> m_highlighters; idvaluemap<std::string, HighlighterFunc> m_highlighters;