From 66f15cf4ad8b0127f93503cad41d570a7c9f5d72 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 7 Jun 2020 13:45:03 +1000 Subject: [PATCH] Fix select wiping captures It turns out `v = std::move(v)` with v a std::vector is not a no-op, it clears the vector. --- src/normal.cc | 10 ++++++---- test/regression/3544-capture-get-lost/cmd | 1 + test/regression/3544-capture-get-lost/in | 1 + test/regression/3544-capture-get-lost/out | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/regression/3544-capture-get-lost/cmd create mode 100644 test/regression/3544-capture-get-lost/in create mode 100644 test/regression/3544-capture-get-lost/out diff --git a/src/normal.cc b/src/normal.cc index 8796c86f..beb880f9 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -93,7 +93,7 @@ void select(Context& context, T func) else { auto main_index = selections.main_index(); - auto new_end = selections.begin(); + size_t new_size = 0; for (size_t i = 0; i < selections.size(); ++i) { auto& sel = selections[i]; @@ -114,13 +114,15 @@ void select(Context& context, T func) } if (not res->captures().empty()) sel.captures() = std::move(res->captures()); - *new_end++ = std::move(sel); + if (i != new_size) + selections[new_size] = std::move(sel); + ++new_size; } - if (new_end == selections.begin()) + if (new_size == 0) throw no_selections_remaining{}; selections.set_main_index(main_index); - selections.remove_from(new_end - selections.begin()); + selections.remove_from(new_size); } selections.sort_and_merge_overlapping(); diff --git a/test/regression/3544-capture-get-lost/cmd b/test/regression/3544-capture-get-lost/cmd new file mode 100644 index 00000000..9f035b0f --- /dev/null +++ b/test/regression/3544-capture-get-lost/cmd @@ -0,0 +1 @@ +/(a)xcx1x diff --git a/test/regression/3544-capture-get-lost/in b/test/regression/3544-capture-get-lost/in new file mode 100644 index 00000000..9d52df39 --- /dev/null +++ b/test/regression/3544-capture-get-lost/in @@ -0,0 +1 @@ +xax diff --git a/test/regression/3544-capture-get-lost/out b/test/regression/3544-capture-get-lost/out new file mode 100644 index 00000000..9d52df39 --- /dev/null +++ b/test/regression/3544-capture-get-lost/out @@ -0,0 +1 @@ +xax