From 3c8df764be5ca2dc2ff423258ee7d14eb5409db2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 30 Jul 2013 19:09:36 +0100 Subject: [PATCH] fix insert mode erase utf-8 handling, add unit test --- src/editor.cc | 4 +++- src/unit_tests.cc | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/editor.cc b/src/editor.cc index c03fd396c..ae156041e 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -558,8 +558,10 @@ void IncrementalInserter::erase() auto& buffer = m_editor.buffer(); for (auto& sel : m_editor.m_selections) { + if (sel.last() == BufferCoord{0,0}) + continue; auto pos = buffer.iterator_at(sel.last()); - buffer.erase(pos-1, pos); + buffer.erase(utf8::previous(pos), pos); } } diff --git a/src/unit_tests.cc b/src/unit_tests.cc index 5058bb915..c0d8a15b2 100644 --- a/src/unit_tests.cc +++ b/src/unit_tests.cc @@ -94,7 +94,7 @@ void test_editor() 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.select({0,0}); @@ -106,6 +106,13 @@ void test_incremental_inserter() kak_assert(editor.selections().front().last() == BufferCoord{0 COMMA 0}); 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()); }