From ae6ee02cb210c4778868316cbd4fa2d5e194a903 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 19 Oct 2022 20:15:54 +1100 Subject: [PATCH] Refactor insert_output command to avoid intermediate vector This is like a paste with a different source, so the same logic should work. This means we now correctly fix overflowing selections. Fixes #4750 --- src/normal.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 12843565..5f0512d7 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -764,7 +764,6 @@ void insert_output(Context& context, NormalParams params) auto& selections = context.selections(); auto& buffer = context.buffer(); const size_t old_main = selections.main_index(); - Vector ins_range; selections.for_each([&](size_t index, Selection& sel) { selections.set_main_index(index); @@ -772,16 +771,13 @@ void insert_output(Context& context, NormalParams params) cmdline, context, content(context.buffer(), sel), ShellManager::Flags::WaitForStdout); + auto& min = sel.min(); + auto& max = sel.max(); auto range = insert(buffer, sel, paste_pos(buffer, sel, mode, false), out); - ins_range.push_back(range); + min = range.begin; + max = range.end > range.begin ? buffer.char_prev(range.end) : range.begin; }); - - selections.set(ins_range | transform([&buffer](auto& range) { - if (range.empty()) - return Selection{range.begin, range.end}; - return Selection{range.begin, - buffer.char_prev(range.end)}; - }) | gather(), old_main); + selections.set_main_index(old_main); }); }