fix open line above for first line and add a unit test

This commit is contained in:
Maxime Coste 2012-09-03 23:46:04 +02:00
parent c61f9cbe6b
commit 69bebdb44e
2 changed files with 28 additions and 0 deletions

View File

@ -356,7 +356,18 @@ IncrementalInserter::IncrementalInserter(Editor& editor, Mode mode)
}
if (mode == Mode::OpenLineBelow or mode == Mode::OpenLineAbove)
{
insert("\n");
if (mode == Mode::OpenLineAbove)
{
for (auto& sel : m_editor.m_selections.back())
{
// special case, the --first line above did nothing, so we need to compensate now
if (sel.first() == buffer().begin() + 1)
sel = Selection(buffer().begin(), buffer().begin());
}
}
}
}
IncrementalInserter::~IncrementalInserter()

View File

@ -45,6 +45,22 @@ void test_editor()
}
}
void test_incremental_inserter()
{
Buffer buffer("test", Buffer::Type::Scratch, "test\n\nyoupi\nmatin\n");
Editor editor(buffer);
editor.select(buffer.begin());
{
IncrementalInserter inserter(editor, IncrementalInserter::Mode::OpenLineAbove);
assert(editor.is_editing());
assert(editor.selections().size() == 1);
assert(editor.selections().front().first() == buffer.begin());
assert(editor.selections().front().last() == buffer.begin());
assert(*buffer.begin() == L'\n');
}
assert(not editor.is_editing());
}
void test_string()
{
assert(int_to_str(124) == "124");
@ -65,4 +81,5 @@ void run_unit_tests()
test_string();
test_buffer();
test_editor();
test_incremental_inserter();
}