summaryrefslogtreecommitdiff
path: root/src/display_buffer.cc
blob: 576e5a1424ed55aa23ebb34397c0f54454f05ab2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "display_buffer.hh"

#include "assert.hh"
#include "utf8.hh"

namespace Kakoune
{

DisplayLine::iterator DisplayLine::split(iterator it, BufferIterator pos)
{
    assert(it->content.type() == AtomContent::BufferRange);
    assert(it->content.begin() < pos);
    assert(it->content.end() > pos);

    assert(utf8::is_character_start(pos));

    DisplayAtom atom = *it;
    atom.content.m_end = pos;
    it->content.m_begin = pos;
    return m_atoms.insert(it, std::move(atom));
}

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);
}

}