Editor: fix replace at end of buffer

This commit is contained in:
Maxime Coste 2013-03-13 14:26:20 +01:00
parent c1db67e31a
commit 0f957b3743
2 changed files with 16 additions and 9 deletions

View File

@ -83,7 +83,7 @@ void Editor::insert(const String& str, InsertMode mode)
{
BufferIterator pos = prepare_insert(*m_buffer, sel, mode);
m_buffer->insert(pos, str);
if (mode == InsertMode::Replace)
if (mode == InsertMode::Replace and not pos.is_end())
{
sel.first() = pos;
sel.last() = str.empty() ? pos : utf8::character_start(pos + str.length() - 1);
@ -105,7 +105,7 @@ void Editor::insert(const memoryview<String>& strings, InsertMode mode)
BufferIterator pos = prepare_insert(*m_buffer, sel, mode);
const String& str = strings[std::min(i, strings.size()-1)];
m_buffer->insert(pos, str);
if (mode == InsertMode::Replace)
if (mode == InsertMode::Replace and not pos.is_end())
{
sel.first() = pos;
sel.last() = str.empty() ? pos : utf8::character_start(pos + str.length() - 1);

View File

@ -55,15 +55,22 @@ void test_editor()
Buffer buffer("test", Buffer::Flags::None, { "test\n", "\n", "youpi\n" });
Editor editor(buffer);
using namespace std::placeholders;
editor.select(select_whole_buffer);
editor.multi_select(std::bind(select_all_matches, _1, "\\n\\h*"));
for (auto& sel : editor.selections())
{
assert(*sel.begin() == '\n');
editor.buffer().erase(sel.begin(), sel.end());
scoped_edition edition{editor};
editor.select(select_whole_buffer);
editor.multi_select(std::bind(select_all_matches, std::placeholders::_1, "\\n\\h*"));
for (auto& sel : editor.selections())
{
assert(*sel.begin() == '\n');
editor.buffer().erase(sel.begin(), sel.end());
}
}
editor.undo();
Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() };
editor.select(sel, SelectMode::Replace);
editor.insert("",InsertMode::Replace);
assert(not editor.selections().back().first().is_end());
}
void test_incremental_inserter()