buffer end should not be in a selection

This commit is contained in:
Maxime Coste 2013-05-23 19:38:51 +02:00
parent 462da52218
commit 9a80a58ff4
3 changed files with 5 additions and 3 deletions

View File

@ -32,8 +32,8 @@ String Range::content() const
void Range::check_invariant() const void Range::check_invariant() const
{ {
#ifdef KAK_DEBUG #ifdef KAK_DEBUG
kak_assert(m_first.is_valid()); kak_assert(m_first.is_valid() and not m_first.is_end());
kak_assert(m_last.is_valid()); 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_first));
kak_assert(utf8::is_character_start(m_last)); kak_assert(utf8::is_character_start(m_last));
#endif #endif

View File

@ -504,6 +504,8 @@ Selection select_whole_lines(const Selection& selection)
++to_line_start; ++to_line_start;
skip_while(to_line_end, [](char cur) { return not is_eol(cur); }); 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); return Selection(first, last);
} }

View File

@ -67,7 +67,7 @@ void test_editor()
} }
editor.undo(); 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.select(sel, SelectMode::Replace);
editor.insert("",InsertMode::Replace); editor.insert("",InsertMode::Replace);
kak_assert(not editor.main_selection().first().is_end()); kak_assert(not editor.main_selection().first().is_end());