Window: use an idvaluemap to store highlighters

This commit is contained in:
Maxime Coste 2011-12-02 14:20:11 +00:00
parent a5a726d291
commit 4252e0d610
3 changed files with 14 additions and 25 deletions

View File

@ -107,6 +107,12 @@ bool contains(const Container& container, const T& value)
!= container.end();
}
inline std::string str_to_str(const std::string& str)
{
return str;
}
}
#endif // utils_hh_INCLUDED

View File

@ -349,37 +349,20 @@ std::string Window::status_line() const
void Window::add_highlighter(HighlighterAndId&& highlighter)
{
for (auto it = m_highlighters.begin(); it != m_highlighters.end(); ++it)
{
if (it->first == highlighter.first)
throw highlighter_id_not_unique(highlighter.first);
}
m_highlighters.push_back(highlighter);
if (m_highlighters.contains(highlighter.first))
throw highlighter_id_not_unique(highlighter.first);
m_highlighters.append(highlighter);
}
void Window::remove_highlighter(const std::string& id)
{
for (auto it = m_highlighters.begin(); it != m_highlighters.end(); ++it)
{
if (it->first == id)
{
m_highlighters.erase(it);
return;
}
}
m_highlighters.remove(id);
}
CandidateList Window::complete_highlighterid(const std::string& prefix,
size_t cursor_pos)
size_t cursor_pos)
{
std::string real_prefix = prefix.substr(0, cursor_pos);
CandidateList result;
for (auto& highlighter : m_highlighters)
{
if (highlighter.first.substr(0, real_prefix.length()) == real_prefix)
result.push_back(highlighter.first);
}
return result;
return m_highlighters.complete_id<str_to_str>(prefix, cursor_pos);
}

View File

@ -8,6 +8,7 @@
#include "display_buffer.hh"
#include "completion.hh"
#include "highlighter.hh"
#include "idvaluemap.hh"
namespace Kakoune
{
@ -121,8 +122,7 @@ private:
SelectionList m_selections;
DisplayBuffer m_display_buffer;
typedef std::vector<HighlighterAndId> HighlighterList;
HighlighterList m_highlighters;
idvaluemap<std::string, HighlighterFunc> m_highlighters;
};
class IncrementalInserter