2014-06-10 20:58:02 +02:00
|
|
|
#include "highlighter_group.hh"
|
|
|
|
|
2014-12-23 14:34:21 +01:00
|
|
|
#include "containers.hh"
|
|
|
|
|
2014-06-10 20:58:02 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
void HighlighterGroup::highlight(const Context& context, HighlightFlags flags,
|
2014-12-02 20:56:17 +01:00
|
|
|
DisplayBuffer& display_buffer, BufferRange range)
|
2014-06-10 20:58:02 +02:00
|
|
|
{
|
|
|
|
for (auto& hl : m_highlighters)
|
2014-12-02 20:56:17 +01:00
|
|
|
hl.second->highlight(context, flags, display_buffer, range);
|
2014-06-10 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
void HighlighterGroup::add_child(HighlighterAndId&& hl)
|
2014-06-10 20:58:02 +02:00
|
|
|
{
|
|
|
|
if (m_highlighters.contains(hl.first))
|
|
|
|
throw runtime_error("duplicate id: " + hl.first);
|
|
|
|
|
|
|
|
m_highlighters.append(std::move(hl));
|
|
|
|
}
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
void HighlighterGroup::remove_child(StringView id)
|
2014-06-10 20:58:02 +02:00
|
|
|
{
|
2014-10-22 01:20:09 +02:00
|
|
|
m_highlighters.remove(id);
|
2014-06-10 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
Highlighter& HighlighterGroup::get_child(StringView path)
|
2014-06-12 22:52:23 +02:00
|
|
|
{
|
2014-10-22 01:20:09 +02:00
|
|
|
auto sep_it = find(path, '/');
|
2014-06-12 22:52:23 +02:00
|
|
|
StringView id(path.begin(), sep_it);
|
|
|
|
auto it = m_highlighters.find(id);
|
|
|
|
if (it == m_highlighters.end())
|
2014-10-22 01:20:09 +02:00
|
|
|
throw child_not_found("no such id: "_str + id);
|
2014-06-15 17:04:38 +02:00
|
|
|
if (sep_it == path.end())
|
2014-10-22 01:20:09 +02:00
|
|
|
return *it->second;
|
2014-06-10 22:35:03 +02:00
|
|
|
else
|
2014-10-22 01:20:09 +02:00
|
|
|
return it->second->get_child({sep_it+1, path.end()});
|
2014-06-10 22:35:03 +02:00
|
|
|
}
|
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
Completions HighlighterGroup::complete_child(StringView path, ByteCount cursor_pos, bool group) const
|
2014-06-12 22:52:23 +02:00
|
|
|
{
|
2014-10-22 01:20:09 +02:00
|
|
|
auto sep_it = find(path, '/');
|
2014-06-12 22:52:23 +02:00
|
|
|
if (sep_it != path.end())
|
2014-06-15 17:04:38 +02:00
|
|
|
{
|
2014-10-22 01:20:09 +02:00
|
|
|
ByteCount offset = sep_it+1 - path.begin();
|
|
|
|
Highlighter& hl = const_cast<HighlighterGroup*>(this)->get_child({path.begin(), sep_it});
|
|
|
|
return offset_pos(hl.complete_child(path.substr(offset), cursor_pos - offset, group), offset);
|
2014-06-15 17:04:38 +02:00
|
|
|
}
|
|
|
|
|
2014-12-23 14:54:09 +01:00
|
|
|
using ValueType = HighlighterMap::value_type;
|
|
|
|
auto c = transformed(filtered(m_highlighters,
|
|
|
|
[=](const ValueType& hl)
|
|
|
|
{ return not group or hl.second->has_children(); }),
|
|
|
|
HighlighterMap::get_id);
|
|
|
|
return { 0, 0, complete(path, cursor_pos, c) };
|
2014-06-15 17:04:38 +02:00
|
|
|
}
|
|
|
|
|
2014-06-10 20:58:02 +02:00
|
|
|
}
|