blob: bc156f26ded767344b1e618413b4f9ecca1bc598 (
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
46
|
#include "selection.hh"
#include "utf8.hh"
namespace Kakoune
{
void Range::merge_with(const Range& range)
{
if (m_first < m_last)
m_first = std::min(m_first, range.m_first);
if (m_first > m_last)
m_first = std::max(m_first, range.m_first);
m_last = range.m_last;
}
BufferIterator Range::begin() const
{
return std::min(m_first, m_last);
}
BufferIterator Range::end() const
{
return utf8::next(std::max(m_first, m_last));
}
void Range::check_invariant() const
{
assert(utf8::is_character_start(first()));
assert(utf8::is_character_start(last()));
}
static void avoid_eol(BufferIterator& it)
{
const auto column = it.column();
if (column != 0 and column == it.buffer().line_length(it.line()) - 1)
it = utf8::previous(it);
}
void Selection::avoid_eol()
{
Kakoune::avoid_eol(first());
Kakoune::avoid_eol(last());
}
}
|