diff --git a/src/utils.hh b/src/utils.hh index 6bfdb907d..5a46b4fde 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -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 diff --git a/src/window.cc b/src/window.cc index 646bc999a..469d435b7 100644 --- a/src/window.cc +++ b/src/window.cc @@ -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(prefix, cursor_pos); } diff --git a/src/window.hh b/src/window.hh index 0f989ece7..fa64d59bf 100644 --- a/src/window.hh +++ b/src/window.hh @@ -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 HighlighterList; - HighlighterList m_highlighters; + idvaluemap m_highlighters; }; class IncrementalInserter