2011-09-02 20:51:20 +04:00
|
|
|
#include "display_buffer.hh"
|
|
|
|
|
2011-09-29 13:10:27 +04:00
|
|
|
#include "assert.hh"
|
2011-09-29 12:55:08 +04:00
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-07-13 01:19:10 +04:00
|
|
|
DisplayLine::iterator DisplayLine::split(iterator it, BufferIterator pos)
|
2011-10-15 08:45:49 +04:00
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(it->content.type() == AtomContent::BufferRange);
|
|
|
|
kak_assert(it->content.begin() < pos);
|
|
|
|
kak_assert(it->content.end() > pos);
|
2011-10-15 08:45:49 +04:00
|
|
|
|
2012-07-13 01:19:10 +04:00
|
|
|
DisplayAtom atom = *it;
|
2012-10-08 16:28:38 +04:00
|
|
|
atom.content.m_end = pos;
|
|
|
|
it->content.m_begin = pos;
|
2012-07-13 01:19:10 +04:00
|
|
|
return m_atoms.insert(it, std::move(atom));
|
2011-09-29 13:10:27 +04:00
|
|
|
}
|
|
|
|
|
2012-10-22 15:20:02 +04:00
|
|
|
void DisplayLine::optimize()
|
|
|
|
{
|
2013-05-02 20:57:15 +04:00
|
|
|
if (m_atoms.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto atom_it = m_atoms.begin();
|
|
|
|
auto next_atom_it = atom_it + 1;
|
|
|
|
while (next_atom_it != m_atoms.end())
|
2012-10-22 15:20:02 +04:00
|
|
|
{
|
2013-05-02 20:57:15 +04:00
|
|
|
auto& atom = *atom_it;
|
|
|
|
auto& next_atom = *next_atom_it;
|
|
|
|
bool merged = false;
|
2012-10-22 15:20:02 +04:00
|
|
|
|
2013-05-02 20:57:15 +04:00
|
|
|
if (atom.colors == next_atom.colors and
|
|
|
|
atom.attribute == next_atom.attribute and
|
|
|
|
atom.content.type() == next_atom.content.type())
|
|
|
|
{
|
|
|
|
auto type = atom.content.type();
|
|
|
|
if ((type == AtomContent::BufferRange or
|
|
|
|
type == AtomContent::ReplacedBufferRange) and
|
2012-10-22 15:20:02 +04:00
|
|
|
next_atom.content.begin() == atom.content.end())
|
|
|
|
{
|
|
|
|
atom.content.m_end = next_atom.content.end();
|
2013-05-02 20:57:15 +04:00
|
|
|
if (type == AtomContent::ReplacedBufferRange)
|
|
|
|
atom.content.m_text += next_atom.content.m_text;
|
|
|
|
merged = true;
|
|
|
|
}
|
|
|
|
if (type == AtomContent::Text)
|
|
|
|
{
|
|
|
|
atom.content.m_text += next_atom.content.m_text;
|
|
|
|
merged = true;
|
2012-10-22 15:20:02 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-02 20:57:15 +04:00
|
|
|
if (merged)
|
|
|
|
next_atom_it = m_atoms.erase(next_atom_it);
|
|
|
|
else
|
|
|
|
atom_it = next_atom_it++;
|
2012-10-22 15:20:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 20:50:00 +04:00
|
|
|
CharCount DisplayLine::length() const
|
|
|
|
{
|
|
|
|
CharCount len = 0;
|
|
|
|
for (auto& atom : m_atoms)
|
|
|
|
len += atom.content.length();
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2012-07-13 01:51:13 +04: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();
|
|
|
|
}
|
|
|
|
}
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_range.first.is_valid() and m_range.second.is_valid());
|
|
|
|
kak_assert(m_range.first <= m_range.second);
|
2012-07-13 01:51:13 +04:00
|
|
|
}
|
|
|
|
|
2012-10-22 15:20:02 +04:00
|
|
|
void DisplayBuffer::optimize()
|
|
|
|
{
|
|
|
|
for (auto& line : m_lines)
|
|
|
|
line.optimize();
|
|
|
|
}
|
2011-09-02 20:51:20 +04:00
|
|
|
}
|