1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-22 02:51:32 +03:00

fix insert mode erase utf-8 handling, add unit test

This commit is contained in:
Maxime Coste 2013-07-30 19:09:36 +01:00
parent 59dae9148b
commit 3c8df764be
2 changed files with 11 additions and 2 deletions

View File

@ -558,8 +558,10 @@ void IncrementalInserter::erase()
auto& buffer = m_editor.buffer(); auto& buffer = m_editor.buffer();
for (auto& sel : m_editor.m_selections) for (auto& sel : m_editor.m_selections)
{ {
if (sel.last() == BufferCoord{0,0})
continue;
auto pos = buffer.iterator_at(sel.last()); auto pos = buffer.iterator_at(sel.last());
buffer.erase(pos-1, pos); buffer.erase(utf8::previous(pos), pos);
} }
} }

View File

@ -94,7 +94,7 @@ void test_editor()
void test_incremental_inserter() void test_incremental_inserter()
{ {
Buffer buffer("test", Buffer::Flags::None, { "test\n", "\n", "youpi\n", "matin\n" }); Buffer buffer("test", Buffer::Flags::None, { "test\n", "\n", "yoüpi\n", "matin\n" });
Editor editor(buffer); Editor editor(buffer);
editor.select({0,0}); editor.select({0,0});
@ -106,6 +106,13 @@ void test_incremental_inserter()
kak_assert(editor.selections().front().last() == BufferCoord{0 COMMA 0}); kak_assert(editor.selections().front().last() == BufferCoord{0 COMMA 0});
kak_assert(*buffer.begin() == L'\n'); kak_assert(*buffer.begin() == L'\n');
} }
// check utf-8 erase
editor.select({3,4});
{
IncrementalInserter inserter(editor, InsertMode::Insert);
inserter.erase();
kak_assert(editor.selections().back().last() == BufferCoord{3 COMMA 2});
}
kak_assert(not editor.is_editing()); kak_assert(not editor.is_editing());
} }