mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 12:36:11 +03:00
Window: use an idvaluemap to store highlighters
This commit is contained in:
parent
a5a726d291
commit
4252e0d610
@ -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
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user