Use SelectionList::insert in InputModes::Insert

This commit is contained in:
Maxime Coste 2014-05-25 22:59:29 +01:00
parent b2621ca140
commit 51eae8026b
3 changed files with 6 additions and 16 deletions

View File

@ -759,26 +759,13 @@ private:
void insert(memoryview<String> strings) void insert(memoryview<String> strings)
{ {
auto& buffer = context().buffer(); context().selections().insert(strings, InsertMode::InsertCursor);
auto& selections = context().selections();
for (size_t i = 0; i < selections.size(); ++i)
{
size_t index = selections.size() - 1 - i;
const String& str = strings[std::min(index, strings.size()-1)];
buffer.insert(buffer.iterator_at(selections[index].cursor()),
str);
}
selections.update();
} }
void insert(Codepoint key) void insert(Codepoint key)
{ {
auto str = codepoint_to_str(key); auto str = codepoint_to_str(key);
auto& buffer = context().buffer(); context().selections().insert(str, InsertMode::InsertCursor);
auto& selections = context().selections();
for (auto& sel : reversed(selections))
buffer.insert(buffer.iterator_at(sel.cursor()), str);
selections.update();
context().hooks().run_hook("InsertChar", str, context()); context().hooks().run_hook("InsertChar", str, context());
} }
@ -828,6 +815,7 @@ private:
cursor = anchor; cursor = anchor;
break; break;
case InsertMode::InsertAtNextLineBegin: case InsertMode::InsertAtNextLineBegin:
case InsertMode::InsertCursor:
kak_assert(false); // not implemented kak_assert(false); // not implemented
break; break;
} }

View File

@ -239,6 +239,8 @@ BufferIterator prepare_insert(Buffer& buffer, const Selection& sel, InsertMode m
{ {
case InsertMode::Insert: case InsertMode::Insert:
return buffer.iterator_at(sel.min()); return buffer.iterator_at(sel.min());
case InsertMode::InsertCursor:
return buffer.iterator_at(sel.cursor());
case InsertMode::Replace: case InsertMode::Replace:
return erase(buffer, sel); return erase(buffer, sel);
case InsertMode::Append: case InsertMode::Append:
@ -295,7 +297,6 @@ void SelectionList::insert(memoryview<String> strings, InsertMode mode)
} }
} }
update(); update();
avoid_eol();
check_invariant(); check_invariant();
m_buffer->check_invariant(); m_buffer->check_invariant();
} }

View File

@ -58,6 +58,7 @@ static bool compare_selections(const Selection& lhs, const Selection& rhs)
enum class InsertMode : unsigned enum class InsertMode : unsigned
{ {
Insert, Insert,
InsertCursor,
Append, Append,
Replace, Replace,
InsertAtLineBegin, InsertAtLineBegin,