From 2809ce00dee77f219275d79ae5e245f6801d5416 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 23 Oct 2016 19:54:40 +0100 Subject: [PATCH] Set main selection index to the current sel when piping different selections Fixes #884 --- src/normal.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index a22a4c91..2f7e3497 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -410,12 +410,15 @@ void pipe(Context& context, NormalParams) Buffer& buffer = context.buffer(); SelectionList& selections = context.selections(); + const int old_main = selections.main_index(); + auto restore_main = on_scope_end([&] { selections.set_main_index(old_main); }); if (replace) { Vector strings; - for (auto& sel : selections) + for (int i = 0; i < selections.size(); ++i) { - String in = content(buffer, sel); + selections.set_main_index(i); + String in = content(buffer, selections.main()); const bool insert_eol = in.back() != '\n'; if (insert_eol) in += '\n'; @@ -432,10 +435,13 @@ void pipe(Context& context, NormalParams) } else { - for (auto& sel : selections) + for (int i = 0; i < selections.size(); ++i) + { + selections.set_main_index(i); ShellManager::instance().eval(real_cmd, context, - content(buffer, sel), + content(buffer, selections.main()), ShellManager::Flags::None); + } } }); }