summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-03-13 14:26:20 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-03-13 14:37:03 +0100
commit0f957b374338ca5eba3bf4e7667c79a29fc6a73a (patch)
tree069c7546b485d3ee9581f4a8a6cab2dda018a868 /src
parentc1db67e31a18a723f455fa0b93c09f01100fcb59 (diff)
Editor: fix replace at end of buffer
Diffstat (limited to 'src')
-rw-r--r--src/editor.cc4
-rw-r--r--src/unit_tests.cc21
2 files changed, 16 insertions, 9 deletions
diff --git a/src/editor.cc b/src/editor.cc
index 476e5244..0f8e3a2c 100644
--- a/src/editor.cc
+++ b/src/editor.cc
@@ -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);
diff --git a/src/unit_tests.cc b/src/unit_tests.cc
index a092fd5c..09ad7f4e 100644
--- a/src/unit_tests.cc
+++ b/src/unit_tests.cc
@@ -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()