selections should always point to an utf8 character sequence start byte
This commit is contained in:
parent
f2e98f700e
commit
5a267ab627
|
@ -132,6 +132,7 @@ public:
|
|||
BufferIterator end() const;
|
||||
CharCount character_count() const;
|
||||
LineCount line_count() const;
|
||||
CharCount line_length(LineCount line) const;
|
||||
|
||||
// returns an iterator at given coordinates. line_and_column is
|
||||
// clamped according to avoid_eol.
|
||||
|
@ -206,8 +207,6 @@ private:
|
|||
void do_insert(const BufferIterator& pos, const String& content);
|
||||
void do_erase(const BufferIterator& pos, CharCount length);
|
||||
|
||||
CharCount line_length(LineCount line) const;
|
||||
|
||||
String m_name;
|
||||
const Type m_type;
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include "selection.hh"
|
||||
|
||||
#include "utf8.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
Selection::Selection(const BufferIterator& first, const BufferIterator& last)
|
||||
: m_first(first), m_last(last)
|
||||
{
|
||||
check_invariant();
|
||||
register_with_buffer();
|
||||
}
|
||||
|
||||
|
@ -42,7 +45,7 @@ BufferIterator Selection::begin() const
|
|||
|
||||
BufferIterator Selection::end() const
|
||||
{
|
||||
return std::max(m_first, m_last) + 1;
|
||||
return utf8::next(std::max(m_first, m_last));
|
||||
}
|
||||
|
||||
void Selection::merge_with(const Selection& selection)
|
||||
|
@ -54,22 +57,31 @@ void Selection::merge_with(const Selection& selection)
|
|||
m_last = selection.m_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()
|
||||
{
|
||||
m_first.clamp(true);
|
||||
m_last.clamp(true);
|
||||
Kakoune::avoid_eol(m_first);
|
||||
Kakoune::avoid_eol(m_last);
|
||||
}
|
||||
|
||||
void Selection::on_insert(const BufferIterator& begin, const BufferIterator& end)
|
||||
{
|
||||
m_first.on_insert(begin.coord(), end.coord());
|
||||
m_last.on_insert(begin.coord(), end.coord());
|
||||
check_invariant();
|
||||
}
|
||||
|
||||
void Selection::on_erase(const BufferIterator& begin, const BufferIterator& end)
|
||||
{
|
||||
m_first.on_erase(begin.coord(), end.coord());
|
||||
m_last.on_erase(begin.coord(), end.coord());
|
||||
check_invariant();
|
||||
}
|
||||
|
||||
void Selection::register_with_buffer()
|
||||
|
@ -84,4 +96,10 @@ void Selection::unregister_with_buffer()
|
|||
buffer.remove_change_listener(*this);
|
||||
}
|
||||
|
||||
void Selection::check_invariant() const
|
||||
{
|
||||
assert(utf8::is_character_start(m_first));
|
||||
assert(utf8::is_character_start(m_last));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ private:
|
|||
void on_erase(const BufferIterator& begin,
|
||||
const BufferIterator& end) override;
|
||||
|
||||
void check_invariant() const;
|
||||
|
||||
BufferIterator m_first;
|
||||
BufferIterator m_last;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user