mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-22 19:11:40 +03:00
cfd7ee049a
this avoids a lot of unnecessary (add|remove)_change_listener as creating temporary Selections do not call that anymore. Use can choose between a SelectionList which or a DynamicSelectionList depending on wethear the buffer will be modified or not during the selections lifetime.
47 lines
890 B
C++
47 lines
890 B
C++
#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());
|
|
}
|
|
|
|
}
|