diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-07-19 17:42:41 +0200 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-07-19 17:42:41 +0200 |
| commit | d3f438810e12925b6fcd4718db0bb989a84348ee (patch) | |
| tree | 525af8003d1fe327f43e7ab408994af6d38b3a5f /src/normal.cc | |
| parent | d1de9912c028d265130a6fb163f48e76fee2aa5e (diff) | |
Fix main selection handling in keep pipe ($)
$kak_reg_hash will properly contain the current selection index when
executing the shell command, fixing its use.
Fixes #1503
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/normal.cc b/src/normal.cc index 6932509c..fd44110f 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1003,15 +1003,27 @@ void keep_pipe(Context& context, NormalParams) const Buffer& buffer = context.buffer(); auto& shell_manager = ShellManager::instance(); Vector<Selection> keep; - for (auto& sel : context.selections()) + + auto& selections = context.selections(); + const size_t old_main = selections.main_index(); + size_t new_main = -1; + for (int i = 0; i < selections.size(); ++i) { + auto& sel = selections[i]; + selections.set_main_index(i); if (shell_manager.eval(cmdline, context, content(buffer, sel), ShellManager::Flags::None).second == 0) + { keep.push_back(sel); + if (i >= old_main and new_main == (size_t)-1) + new_main = keep.size() - 1; + } } if (keep.empty()) throw runtime_error("no selections remaining"); - context.selections_write_only() = std::move(keep); + if (new_main == -1) + new_main = keep.size() - 1; + context.selections_write_only().set(std::move(keep), new_main); }); } template<bool indent_empty = false> |
