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(); != container.end();
} }
inline std::string str_to_str(const std::string& str)
{
return str;
}
} }
#endif // utils_hh_INCLUDED #endif // utils_hh_INCLUDED

View File

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

View File

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