2012-01-31 23:12:06 +04:00
|
|
|
#include "selection.hh"
|
|
|
|
|
2012-10-08 16:26:57 +04:00
|
|
|
#include "utf8.hh"
|
|
|
|
|
2012-01-31 23:12:06 +04:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-11-30 21:32:49 +04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2013-02-27 22:11:25 +04:00
|
|
|
String Range::content() const
|
|
|
|
{
|
|
|
|
return m_first.buffer().string(begin(), end());
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:51:59 +04:00
|
|
|
void Range::check_invariant() const
|
2012-01-31 23:12:06 +04:00
|
|
|
{
|
2013-02-27 22:02:01 +04:00
|
|
|
#ifdef KAK_DEBUG
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_first.is_valid());
|
|
|
|
kak_assert(m_last.is_valid());
|
|
|
|
kak_assert(utf8::is_character_start(m_first));
|
|
|
|
kak_assert(utf8::is_character_start(m_last));
|
2013-02-27 22:02:01 +04:00
|
|
|
#endif
|
2012-01-31 23:12:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-08 16:26:57 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-08-15 20:20:02 +04:00
|
|
|
void Selection::avoid_eol()
|
|
|
|
{
|
2012-11-30 21:32:49 +04:00
|
|
|
Kakoune::avoid_eol(first());
|
|
|
|
Kakoune::avoid_eol(last());
|
2012-08-15 20:20:02 +04:00
|
|
|
}
|
|
|
|
|
2012-01-31 23:12:06 +04:00
|
|
|
}
|