Editor: fix replacement beheviour just before end of line

This commit is contained in:
Maxime Coste 2012-11-23 19:13:47 +01:00
parent dca05ecc73
commit 84db1e2b8c

View File

@ -64,12 +64,17 @@ void Editor::insert(const String& string, InsertMode mode)
{ {
scoped_edition edition(*this); scoped_edition edition(*this);
if (mode == InsertMode::Replace) if (mode == InsertMode::Replace)
erase(); {
// do not call Editor::erase as we do not want to avoid end of lines
for (auto& sel : m_selections)
m_buffer->erase(sel.begin(), sel.end());
}
for (auto& sel : m_selections) for (auto& sel : m_selections)
{ {
BufferIterator pos = prepare_insert(*m_buffer, sel.selection, mode); BufferIterator pos = prepare_insert(*m_buffer, sel.selection, mode);
m_buffer->insert(pos, string); m_buffer->insert(pos, string);
sel.selection.avoid_eol();
} }
} }
@ -77,16 +82,21 @@ void Editor::insert(const memoryview<String>& strings, InsertMode mode)
{ {
scoped_edition edition(*this); scoped_edition edition(*this);
if (mode == InsertMode::Replace) if (mode == InsertMode::Replace)
erase(); {
// do not call Editor::erase as we do not want to avoid end of lines
for (auto& sel : m_selections)
m_buffer->erase(sel.begin(), sel.end());
}
if (strings.empty()) if (strings.empty())
return; return;
for (size_t i = 0; i < selections().size(); ++i) for (size_t i = 0; i < selections().size(); ++i)
{ {
BufferIterator pos = prepare_insert(*m_buffer, m_selections[i].selection, mode); Selection& sel = m_selections[i].selection;
BufferIterator pos = prepare_insert(*m_buffer, sel, mode);
size_t index = std::min(i, strings.size()-1); size_t index = std::min(i, strings.size()-1);
m_buffer->insert(pos, strings[index]); m_buffer->insert(pos, strings[index]);
sel.avoid_eol();
} }
} }