From b29cae4d16077c6121e5d4cff00416fd98dfc60c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 19 May 2014 18:59:14 +0100 Subject: [PATCH] Remove duplicated logic and fix insert in Replace mode --- src/normal.cc | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 0e2d3b38..2e68f8cd 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -62,30 +62,6 @@ BufferIterator prepare_insert(Buffer& buffer, const Selection& sel) return {}; } -template -void insert(Buffer& buffer, SelectionList& selections, const String& str) -{ - for (auto& sel : reversed(selections)) - { - auto pos = prepare_insert(buffer, sel); - pos = buffer.insert(pos, str); - if (mode == InsertMode::Replace) - { - if (pos == buffer.end()) - --pos; - sel.anchor() = pos.coord(); - sel.cursor() = str.empty() ? - pos.coord() : (pos + str.byte_count_to(str.char_length() - 1)).coord(); - } - } - if (mode == InsertMode::Replace) - selections.update_timestamp(); - else - selections.update(); - selections.avoid_eol(); - buffer.check_invariant(); -} - template void insert(Buffer& buffer, SelectionList& selections, memoryview strings) { @@ -102,16 +78,15 @@ void insert(Buffer& buffer, SelectionList& selections, memoryview string { if (pos == buffer.end()) --pos; + selections.update(); sel.anchor() = pos.coord(); sel.cursor() = (str.empty() ? pos : pos + str.byte_count_to(str.char_length() - 1)).coord(); } } - if (mode == InsertMode::Replace) - selections.update_timestamp(); - else - selections.update(); + selections.update(); selections.avoid_eol(); + selections.check_invariant(); buffer.check_invariant(); } @@ -788,7 +763,7 @@ void join_select_spaces(Context& context, int) return; context.selections() = selections; ScopedEdition edition(context); - insert(buffer, context.selections(), " "); + insert(buffer, context.selections(), " "_str); } void join(Context& context, int param)