2011-09-02 18:51:20 +02:00
|
|
|
#include "display_buffer.hh"
|
|
|
|
|
2011-09-29 11:10:27 +02:00
|
|
|
#include "assert.hh"
|
2012-10-08 14:28:54 +02:00
|
|
|
#include "utf8.hh"
|
2011-09-29 10:55:08 +02:00
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-07-12 23:19:10 +02:00
|
|
|
DisplayLine::iterator DisplayLine::split(iterator it, BufferIterator pos)
|
2011-10-15 06:45:49 +02:00
|
|
|
{
|
2012-07-12 23:19:10 +02:00
|
|
|
assert(it->content.type() == AtomContent::BufferRange);
|
|
|
|
assert(it->content.begin() < pos);
|
|
|
|
assert(it->content.end() > pos);
|
2011-10-15 06:45:49 +02:00
|
|
|
|
2012-10-08 14:28:54 +02:00
|
|
|
assert(utf8::is_character_start(pos));
|
|
|
|
|
2012-07-12 23:19:10 +02:00
|
|
|
DisplayAtom atom = *it;
|
2012-10-08 14:28:38 +02:00
|
|
|
atom.content.m_end = pos;
|
|
|
|
it->content.m_begin = pos;
|
2012-07-12 23:19:10 +02:00
|
|
|
return m_atoms.insert(it, std::move(atom));
|
2011-09-29 11:10:27 +02:00
|
|
|
}
|
|
|
|
|
2012-10-22 13:20:02 +02:00
|
|
|
void DisplayLine::optimize()
|
|
|
|
{
|
|
|
|
for (auto atom_it = m_atoms.begin(); atom_it != m_atoms.end(); ++atom_it)
|
|
|
|
{
|
|
|
|
decltype(atom_it) next_atom_it;
|
|
|
|
while ((next_atom_it = atom_it + 1) != m_atoms.end())
|
|
|
|
{
|
|
|
|
auto& atom = *atom_it;
|
|
|
|
auto& next_atom = *next_atom_it;
|
|
|
|
|
|
|
|
if (atom.fg_color == next_atom.fg_color and
|
|
|
|
atom.bg_color == next_atom.bg_color and
|
|
|
|
atom.attribute == next_atom.attribute and
|
|
|
|
atom.content.type() == AtomContent::BufferRange and
|
|
|
|
next_atom.content.type() == AtomContent::BufferRange and
|
|
|
|
next_atom.content.begin() == atom.content.end())
|
|
|
|
{
|
|
|
|
atom.content.m_end = next_atom.content.end();
|
|
|
|
atom_it = m_atoms.erase(next_atom_it) - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-12 23:51:13 +02:00
|
|
|
void DisplayBuffer::compute_range()
|
|
|
|
{
|
|
|
|
m_range.first = BufferIterator();
|
|
|
|
m_range.second = BufferIterator();
|
|
|
|
for (auto& line : m_lines)
|
|
|
|
{
|
|
|
|
for (auto& atom : line)
|
|
|
|
{
|
|
|
|
if (not atom.content.has_buffer_range())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (not m_range.first.is_valid() or m_range.first > atom.content.begin())
|
|
|
|
m_range.first = atom.content.begin();
|
|
|
|
|
|
|
|
if (not m_range.second.is_valid() or m_range.second < atom.content.end())
|
|
|
|
m_range.second = atom.content.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(m_range.first.is_valid() and m_range.second.is_valid());
|
|
|
|
assert(m_range.first <= m_range.second);
|
|
|
|
}
|
|
|
|
|
2012-10-22 13:20:02 +02:00
|
|
|
void DisplayBuffer::optimize()
|
|
|
|
{
|
|
|
|
for (auto& line : m_lines)
|
|
|
|
line.optimize();
|
|
|
|
}
|
2011-09-02 18:51:20 +02:00
|
|
|
}
|