diff --git a/src/selection.cc b/src/selection.cc index 9c6ca775..cf2b146a 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -32,8 +32,8 @@ String Range::content() const void Range::check_invariant() const { #ifdef KAK_DEBUG - kak_assert(m_first.is_valid()); - kak_assert(m_last.is_valid()); + kak_assert(m_first.is_valid() and not m_first.is_end()); + kak_assert(m_last.is_valid() and not m_last.is_end()); kak_assert(utf8::is_character_start(m_first)); kak_assert(utf8::is_character_start(m_last)); #endif diff --git a/src/selectors.cc b/src/selectors.cc index 818822e6..7fef6ce6 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -504,6 +504,8 @@ Selection select_whole_lines(const Selection& selection) ++to_line_start; skip_while(to_line_end, [](char cur) { return not is_eol(cur); }); + if (is_end(to_line_end)) + --to_line_end; return Selection(first, last); } diff --git a/src/unit_tests.cc b/src/unit_tests.cc index 9c3dfd14..02dc8e87 100644 --- a/src/unit_tests.cc +++ b/src/unit_tests.cc @@ -67,7 +67,7 @@ void test_editor() } editor.undo(); - Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() }; + Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end()-1 }; editor.select(sel, SelectMode::Replace); editor.insert("",InsertMode::Replace); kak_assert(not editor.main_selection().first().is_end());