diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-10-08 14:26:57 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-10-08 14:26:57 +0200 |
| commit | 5a267ab627f52e25e2ae59ab2c19aaa625914b90 (patch) | |
| tree | 6e20cfcf88a7e04096cfd4b7a4c187109ccaa8c9 /src/selection.cc | |
| parent | f2e98f700e405a0cb17be9a6b73daed15f50a165 (diff) | |
selections should always point to an utf8 character sequence start byte
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/selection.cc b/src/selection.cc index ebdea78f..baab004d 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -1,12 +1,15 @@ #include "selection.hh" +#include "utf8.hh" + namespace Kakoune { Selection::Selection(const BufferIterator& first, const BufferIterator& last) : m_first(first), m_last(last) { - register_with_buffer(); + check_invariant(); + register_with_buffer(); } Selection::Selection(const Selection& other) @@ -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)); +} + } |
